[Python-bugs-list] [ python-Feature Requests-414029 ] Request for time.standardtime(secs)

noreply@sourceforge.net noreply@sourceforge.net
Sun, 22 Dec 2002 19:17:35 -0800


Feature Requests item #414029, was opened at 2001-04-05 11:38
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=355470&aid=414029&group_id=5470

Category: Extension Modules
Group: None
Status: Closed
Resolution: Fixed
Priority: 5
Submitted By: Tim Cera (timcera)
Assigned to: Neal Norwitz (nnorwitz)
Summary: Request for time.standardtime(secs)

Initial Comment:
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

----------------------------------------------------------------------

>Comment By: Tim Peters (tim_one)
Date: 2002-12-22 22:17

Message:
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.

----------------------------------------------------------------------

Comment By: Tim Cera (timcera)
Date: 2002-12-21 13:29

Message:
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


----------------------------------------------------------------------

Comment By: Neal Norwitz (nnorwitz)
Date: 2002-12-17 08:22

Message:
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.

----------------------------------------------------------------------

Comment By: Tim Peters (tim_one)
Date: 2002-12-16 23:26

Message:
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.

----------------------------------------------------------------------

Comment By: Neal Norwitz (nnorwitz)
Date: 2002-12-16 23:11

Message:
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?

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=355470&aid=414029&group_id=5470