This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Title: time.utcoffset()
Type: enhancement Stage: resolved
Components: Library (Lib) Versions: Python 3.3
Status: closed Resolution: rejected
Dependencies: Superseder: Add aware local time support to datetime module
View: 9527
Assigned To: belopolsky Nosy List: belopolsky, eric.araujo, pitrou
Priority: normal Keywords:

Created on 2010-01-09 17:15 by techtonik, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (11)
msg97463 - (view) Author: anatoly techtonik (techtonik) Date: 2010-01-09 17:15
The proposal to add the function that will allow to get current UTC offset. Do we need a PEP for this one?

def time.utcoffset():
  """Return current UTC offset in seconds"""
  return -(time.altzone if time.daylight else time.timezone)
msg97472 - (view) Author: Brian Curtin (brian.curtin) * (Python committer) Date: 2010-01-09 21:26
I think this would be nice, but see msg97471 from your ISO timestamp issue. time.daylight should probably be time.localtime().tm_isdst.
msg97509 - (view) Author: anatoly techtonik (techtonik) Date: 2010-01-10 11:45
Answered in msg97503

In the meanwhile it looks like another proposal about RFC format in issue #7584 doesn't account for proper timezone too.
msg99119 - (view) Author: anatoly techtonik (techtonik) Date: 2010-02-09 14:56
Updated Python code according to discussion from aforementioned issue #7582. Unfortunately, I can't find Python source for `time` module to make a proper patch out of it.

def time.utcoffset():
  """Return current UTC offset in seconds"""
  isdst = time.localtime().tm_isdst
  if (time.daylight and isdst):
    return -time.altzone
    return -time.timezone
msg99120 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2010-02-09 15:48
The `time` module is written in C, in Modules/timemodule.c.
If this is too bothersome to write in C, the function could perhaps be added to the datetime module instead.
In any case, we need a proper patch, including unit tests if possible.

(and I agree that anything making the time stuff easier to use is welcome)
msg107172 - (view) Author: Alexander Belopolsky (belopolsky) * (Python committer) Date: 2010-06-06 01:52
I would prefer exposing tm_gmtoff in time.localtime() output. The advantage is that on platforms that support it is struct tm, it will return correct offset for times in the past, not only for the current time. See issue1647654.

On platforms without tm_gmtoff we can fill it with -tm_isdst?timezone:altzone.  The current situation on Linux is just backwards: we are trying to divine altzone by sampling tm_gmtoff and throw tm_gmtoff away.

msg126064 - (view) Author: Alexander Belopolsky (belopolsky) * (Python committer) Date: 2011-01-12 01:44
I am going to close this as superseded by #9527.  All these issues, current, #9527, and #1647654 are really about Python's lack of access to the system timezone information and #9527 seem to be the most appropriate solution.

My specific concern about proposed time.utcoffset() is that you normally need UTC offset together with current time, but localtime() call followed by utcoffset() may lead to a race condition.
msg126217 - (view) Author: anatoly techtonik (techtonik) Date: 2011-01-13 23:27
This one is a different issue. Even though it can not be solved without by #9527, it is not superseded by it. So, better add to dependencies.
msg126218 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2011-01-13 23:39
You can discuss within the comments whether this issue should be re-opened or not, but do not take it upon yourself to change the status on your own once a core developer has already closed an issue as their decision supersedes that of a regular user.
msg126220 - (view) Author: anatoly techtonik (techtonik) Date: 2011-01-14 00:18
I am tired. Do as you wish.
msg126224 - (view) Author: Alexander Belopolsky (belopolsky) * (Python committer) Date: 2011-01-14 04:25
Just to clarify: Anatoly changed the resolution, not status (and I agree that was not appropriate.)  The status was set to "pending" and that would change to "open" automatically if a new comment is posted.

As for the substance of Anatoly's objection - I agree that this proposal is different from #9527.   That is why I set resolution to "rejected" rathe than "duplicate".  This issue can probably be properly classified as a duplicate of #1647654, but I consider #9527 the most promising solution to the problem of finding the system timezone offset.
Date User Action Args
2022-04-11 14:56:56adminsetgithub: 51911
2011-01-14 04:25:28belopolskysetnosy: belopolsky, pitrou, eric.araujo
messages: + msg126224
stage: needs patch -> resolved
2011-01-14 00:19:03techtoniksetnosy: - techtonik
2011-01-14 00:18:42techtoniksetstatus: open -> closed
nosy: belopolsky, pitrou, techtonik, eric.araujo
messages: + msg126220
2011-01-13 23:39:30brett.cannonsetstatus: pending -> open
nosy: - brett.cannon
2011-01-13 23:39:17brett.cannonsetstatus: open -> pending

messages: + msg126218
resolution: rejected
nosy: brett.cannon, belopolsky, pitrou, techtonik, eric.araujo
2011-01-13 23:29:14brian.curtinsetnosy: - brian.curtin
2011-01-13 23:27:56techtoniksetstatus: pending -> open

messages: + msg126217
resolution: rejected -> (no value)
nosy: brett.cannon, belopolsky, pitrou, techtonik, eric.araujo, brian.curtin
2011-01-12 01:44:32belopolskysetstatus: open -> pending
superseder: Add aware local time support to datetime module
messages: + msg126064

nosy: brett.cannon, belopolsky, pitrou, techtonik, eric.araujo, brian.curtin
resolution: rejected
2010-12-01 19:01:00eric.araujosetnosy: + eric.araujo

versions: + Python 3.3, - Python 2.7, Python 3.2
2010-06-06 01:52:05belopolskysetassignee: belopolsky

messages: + msg107172
nosy: + belopolsky
2010-02-09 15:48:15pitrousetnosy: + brett.cannon, pitrou
messages: + msg99120
2010-02-09 14:56:34techtoniksetmessages: + msg99119
2010-01-14 02:41:01brian.curtinsetpriority: normal
stage: needs patch
2010-01-10 11:45:56techtoniksetmessages: + msg97509
2010-01-09 21:26:54brian.curtinsetversions: - Python 3.1
nosy: + brian.curtin

messages: + msg97472

type: enhancement
2010-01-09 17:30:54techtoniksettitle: time.utcoffset(dst=true) -> time.utcoffset()
2010-01-09 17:15:39techtonikcreate