[Zope3-dev] Dates and times
Marius Gedminas
mgedmin@codeworks.lt
Fri, 15 Nov 2002 17:34:06 +0200
On Fri, Nov 15, 2002 at 10:28:10AM -0500, Barry A. Warsaw wrote:
> Can we add time to a datetime? Say I want something to happen at
> 4:30am every day, and I have a datetime for tomorrow at midnight. I
> should be able to add 4 1/2 hours to that datetime to get the target
> datetime. Or, say I want to add 36 hours and 27 minutes to a datetime
> that represents right now. All those things should be possible right?
> I guess the latter example can't use a time value to represent "36
> hours and 27 minutes" if we're limited to a 24 hour range.
There is a datetime.timedelta class for representing time intervals.
You can perform arithmetic on dates and timedeltas (date + timedelta =
date, date - date = timedelta, etc).
A separate 'time of day' class would be different from timedelta in that
it is "anchored" to to the beginning of a day (not a specific day, but
any day).
In my opinion modular arithmetic on time values is the only reasonable
option if you're limited to a 24 hour range, but your email is a perfect
example of why it is too confusing.
Marius Gedminas
--
If something has not yet gone wrong then it would ultimately have been
beneficial for it to go wrong.