You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Use local timezone offset by default in datetime.timezone #58291
bpo-9527: Add aware local time support to datetime module
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
assignee=Noneclosed_at=<Date2012-02-22.04:24:18.376>created_at=<Date2012-02-22.02:27:38.245>labels= ['type-feature', 'library']
title='Use local timezone offset by default in datetime.timezone'updated_at=<Date2012-02-22.04:24:18.375>user='https://github.com/ncoghlan'
The problem with this idea is that while evaluating datetime.datetime.now(datetime.timezone()), python will have to query the real time clock twice (first in timezone() and then in now()). At a particularly unfortunate time this may result in an error. Unlikely? Yes, but I would not board a python powered airplane if this problem was in the standard library.
I gave a lot of thought to the problem of supporting timezone aware local time and bpo-9527 was the best solution I was able to come up with.
Activity
ncoghlan commentedon Feb 22, 2012
Currently, datetime.timezone requires that the offset be specified explicitly.
It would be more convenient if the local offset was used by default.
Since the time module already exposes the offset details for the local timezone, this would just make:
equivalent to the current complex incantation:
Then getting a timezone aware version of the local time would just be:
Similar to the existing spelling for UTC:
(Inspired by http://hyperpolyglot.org/scripting#timezone-offset-notes)
abalkin commentedon Feb 22, 2012
The problem with this idea is that while evaluating datetime.datetime.now(datetime.timezone()), python will have to query the real time clock twice (first in timezone() and then in now()). At a particularly unfortunate time this may result in an error. Unlikely? Yes, but I would not board a python powered airplane if this problem was in the standard library.
I gave a lot of thought to the problem of supporting timezone aware local time and bpo-9527 was the best solution I was able to come up with.
ncoghlan commentedon Feb 22, 2012
Marking as a duplicate of bpo-9527.
If that API is added, the local fixed offset timezone will be accessible as datetime.datetime.localtime().tzinfo which would be simple enough.