[New-bugs-announce] [issue14083] Use local timezone offset by default in datetime.timezone

Nick Coghlan report at bugs.python.org
Wed Feb 22 03:27:40 CET 2012


New submission from Nick Coghlan <ncoghlan at gmail.com>:

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:

  local_tz = datetime.timezone()

equivalent to the current complex incantation:

  local_tz = datetime.timezone(datetime.timedelta(hours=(time.timezone / -3600 + tm.tm_isdst)))

Then getting a timezone aware version of the local time would just be:

  now = datetime.datetime.now(datetime.timezone())

Similar to the existing spelling for UTC:

  now = datetime.datetime.now(datetime.timezone.utc)

(Inspired by http://hyperpolyglot.org/scripting#timezone-offset-notes)

----------
components: Library (Lib)
messages: 153923
nosy: belopolsky, lemburg, ncoghlan, pitrou
priority: normal
severity: normal
stage: needs patch
status: open
title: Use local timezone offset by default in datetime.timezone
type: enhancement
versions: Python 3.3

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue14083>
_______________________________________


More information about the New-bugs-announce mailing list