[Python-bugs-list] [ python-Bugs-665194 ] datetime-RFC2822 roundtripping
SourceForge.net
noreply@sourceforge.net
Sat, 11 Jan 2003 08:32:41 -0800
Bugs item #665194, was opened at 2003-01-09 13:24
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=665194&group_id=5470
Category: None
Group: Feature Request
Status: Open
Resolution: None
Priority: 5
Submitted By: Walter Dörwald (doerwalter)
Assigned to: Nobody/Anonymous (nobody)
Summary: datetime-RFC2822 roundtripping
Initial Comment:
It would be good to have a simply way to convert
between datetime objects and RFC2822 style strings.
>From string to datetime is easy with
datetime.datetime(*email.Utils.parsedate(m)[:7]) (but
this drops the timezone), but the other direction seems
impossible. email.Utils.formatdate takes a timestamp
argument, but AFAICT there's no way to get a timestamp
out of a datetime object.
Of course the best solution (ignoring backwards
compatibility) would be for parsedate und formatdate to
return/accept datetime objects or for datetime to have
the appropriate methods.
----------------------------------------------------------------------
>Comment By: Tim Peters (tim_one)
Date: 2003-01-11 11:32
Message:
Logged In: YES
user_id=31435
Define what totimestamp() should do. The range of
timestamps supported by the *platform* C library (and so
indirectly by Python's time module) isn't defined by any
standard, and isn't easily discoverable either. It may or
may not work before 1970, may or may not after 2038.
datetime covers days far outside that range. Note that
even a double doesn't have enough bits of precision to
cover the full range of datetime values, either.
In contrast, ordinals are wholly under Python's control, so
we can promise surprise-free conversion in both directions.
All we can promise about timestamps is that if the platform
supports a timestamp for a time in datetime's range,
datetime can make sense of it.
----------------------------------------------------------------------
Comment By: Walter Dörwald (doerwalter)
Date: 2003-01-11 07:33
Message:
Logged In: YES
user_id=89016
OK, I'll mark this a feature request.
datetime has fromordinal() and toordinal(), it has
fromtimestamp(), so I'd say a totimestamp() method would be
a logical addition.
----------------------------------------------------------------------
Comment By: Tim Peters (tim_one)
Date: 2003-01-11 00:10
Message:
Logged In: YES
user_id=31435
You can get a timestamp like so:
>>> time.mktime(datetime.date(2002, 1, 1).timetuple())
1009861200.0
>>>
The dates for which this works depends on the platform
mktime implementation, though.
BTW, this sounds a lot more like a new feature request
than a bug!
----------------------------------------------------------------------
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=665194&group_id=5470