toxygen-project / toxygen

Toxygen is pythonic Tox client
GNU General Public License v3.0
280 stars 46 forks source link

Timezones #23

Closed Sorunome closed 8 years ago

Sorunome commented 8 years ago

Toxygen has some timezone stuff off......

example:

sorunome@sorunome-desktop ~ $ date -u
Tue Aug 30 16:31:11 UTC 2016
sorunome@sorunome-desktop ~ $ date
Tue Aug 30 18:31:12 CEST 2016

While toxygen displays as 17:31

sorunome@sorunome-desktop ~ $ ls -l /etc/localtime
lrwxrwxrwx 1 root root 33 Dec  3  2014 /etc/localtime -> /usr/share/zoneinfo/Europe/Berlin
IngvarX commented 8 years ago

For all messages? Try in terminal: python3 import time print(time.strftime('%H:%M')) Does it show current time?

Sorunome commented 8 years ago

Yes, for all messages. Manually running pythons time function does display the correct time as expected.

IngvarX commented 8 years ago

Does it show incorrect time right after message appearance or later, after switching friends?

Sorunome commented 8 years ago

On both, all the time

IngvarX commented 8 years ago

Can you try:

import time
t = time.time()
sec = int(t) - time.timezone
m, s = divmod(sec, 60)
h, m = divmod(m, 60)
d, h = divmod(h, 24)
s = '%02d:%02d' % (h, m)
print(s)
Sorunome commented 8 years ago

That gives the weird time which toxygen displays, the one that is one hour off from the correct one.

Sorunome commented 8 years ago

The issue seems to me being time.timezone here, it seems to be ignoring sumer / wintertime, time.timezone returns -3600 for me, while during the sumertime we are actually 2h away from UTC, not just 1h

IngvarX commented 8 years ago

Yes, timezone produces error. What about

import time
t = time.time()
offset = time.timezone if (time.localtime().tm_isdst == 0) else time.altzone
sec = int(t) + offset
m, s = divmod(sec, 60)
h, m = divmod(m, 60)
d, h = divmod(h, 24)
s = '%02d:%02d' % (h, m)
print(s)
Sorunome commented 8 years ago

That is even more off.

time.daylight appears to be return 1 if there are currently daylight saving times, which means it requires an additional hour offset. (else it appears to return zero)

According to the docs time.timezone only gives the offset without daylight saving time

IngvarX commented 8 years ago

offset = time.timezone if not time.daylight else time.timezone - 3600 should fix this bug

Sorunome commented 8 years ago

why not

offset = time.timezone - time.daylight*3600

IngvarX commented 8 years ago

Also good if time.daylight is int or bool. Fix is coming

Sorunome commented 8 years ago

It appears to be int

IngvarX commented 8 years ago

Fixed in develop