Repository navigation
Conversation
|
Before merging this we need to consider the discussion in celery/celery#4160 . |
| d = d.replace(tzinfo=default_timezone) | ||
| diff = _time() - time() | ||
| return max((d - EPOCH).total_seconds() - diff, 0) | ||
| epoch = datetime.utcfromtimestamp(0).replace(tzinfo=default_timezone) |
There was a problem hiding this comment.
I don't believe that the timezone replacement here is proper. This won't convert the time to the new timezone, but simply replace the internal timezone.
So 9 AM UTC will "become" 9 AM JST.
Likewise, the epoch here might be transformed into "epoch + 9 hours".
what you can go for instead is default_timezone.normalize(datetime.utcfromtimestamp(0)) (you might need to manually add the UTC timezone to the datetime first though)
There was a problem hiding this comment.
This patch make sure the (d - epoch).total_seconds() is calcing in same timezone
There was a problem hiding this comment.
In [22]: from pytz import UTC
In [23]: from pytz.reference import Eastern
In [24]: from datetime import datetime
In [25]: datetime.utcfromtimestamp(0).replace(tzinfo=Eastern) - datetime.utcfrom
...: timestamp(0).replace(tzinfo=UTC)
Out[25]: datetime.timedelta(0, 18000)
replaceing here means that epoch is no longer the the "proper" epoch.
The whole point of storing timezone info in datetimes is to do math without worrying about timezones... so here if you need timezone-aware datetimes, you could just do epoch = datetime.utcfromtimestamp(0).replace(tzinfo=UTC) to get the "timezone-aware" epoch.
|
@shn7798 can we close this now? |
celery task ETA calc with this function, but it only works when timezone is 'UTC'