Closed b6a32436-a7c9-4d21-ae42-d6269ba3a0b2 closed 21 years ago
The time.localtime(secs) function always sets the dst flag to 1 and applies daylight savings time for that time zone. There isn't an easy way to get 'standard' time. A time.standardtime(secs) function would not apply the daylight savings time correction, set the dst flag to 0 (or -1?), but would correct for time zone difference from UTC.
thanks tim cera
Logged In: YES user_id=33168
Tim (Peters), here's another date/time one. This seems to already work for time.gmtime() which returns 0 for tm_isdst. Can this be closed?
Logged In: YES user_id=31435
Unassigned this. I don't know what Tim Cera is asking for, so I suggest we close this unless clarification is forthcoming.
>>> import time
>>> time.localtime(time.time())
(2002, 12, 16, 23, 21, 36, 0, 350, 0)
>>> _.tm_isdst
0
>>>
That is, it's not true that time.localtime() always sets tm_isdst to 1, nor is it true that it always applies a DST adjustment. Perhaps he has a platform bug, but we don't know which platform, or version of Python, he's talking about.
On top of all that, I've no idea what "standard time" means in this context.
Logged In: YES user_id=33168
Tim Cera, I will close this in about a month unless you can provide clarification.
I believe there may have been some issues with the DST flag in earlier versions of Python. However, these have been fixed. Also, with the new Date & Time classes Tim has added for Python 2.3, these should provide the functionality you want.
Logged In: YES user_id=169213
My initial comment/request is really uninformative. :-( I didn't even include which version of Python!
For my job, we collect data time stamped with what we call 'Eastern Standard Time' which has the time zone correction of time.localtime, without the daylight savings time adjustment. The EST term may not be appropriate, but that is what we refer to our time stamps on our data.
I am a little bit better at Python than when I asked for this function. What was once impossible or onerous has become trivial. So...
>>> def standardtime(time_secs_int):
... import time
... return time.gmtime(time_secs_int - time.timezone)
>>> import time
>>> dst = time.mktime((2002, 6, 1, 0, 0, 0, 0, 0, 0))
>>> time.localtime(dst)
(2002, 6, 1, 1, 0, 0, 5, 152, 1)
>>> standardtime(dst)
(2002, 6, 1, 0, 0, 0, 5, 152, 0)
Definitely close this request.
Eagerly waiting to see the new Date and Time classes in 2.3.
thanks tim cera
Logged In: YES user_id=31435
Ah, so your vision of time for EST is always 5 hours west of UTC, regardless of DST. The new datetime module supplies a framework for dealing with time adjustments via so- called "tzinfo classes", but doesn't supply any concrete tzinfo classes. You can easily define your own, though, with any rules you like. For example,
class EST(datetime.tzinfo):
def utcoffset(self, dt): return -300 # minutes
def tzname(self, dt): return "EST"
A Python implementation of the module can be found in Python's CVS nondist/sandbox/datetime, and in Zope3's CVS lib/python/datetime. The C implemenation is in Python's CVS HEAD. So if you're *really* motivated \<wink>, there are 3 ways to play with it now.
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: ```python assignee = None closed_at =
created_at =
labels = ['extension-modules', 'type-feature']
title = 'Request for time.standardtime(secs)'
updated_at =
user = 'https://bugs.python.org/timcera'
```
bugs.python.org fields:
```python
activity =
actor = 'tim.peters'
assignee = 'nnorwitz'
closed = True
closed_date = None
closer = None
components = ['Extension Modules']
creation =
creator = 'timcera'
dependencies = []
files = []
hgrepos = []
issue_num = 414029
keywords = []
message_count = 6.0
messages = ['53113', '53114', '53115', '53116', '53117', '53118']
nosy_count = 3.0
nosy_names = ['tim.peters', 'nnorwitz', 'timcera']
pr_nums = []
priority = 'normal'
resolution = 'fixed'
stage = None
status = 'closed'
superseder = None
type = 'enhancement'
url = 'https://bugs.python.org/issue414029'
versions = []
```