From: Shin, D. <sd...@em...> - 2004-09-16 16:35:57
|
> I would like to rewrite the dates module, and the ticker functions for > dates, to use the python datetime module. Getting dates, timezones, > and daylight savings time right is non-trivial, and I think the > cleanest approach is to require python2.3 and datetime. Ie, I would > jettison support for epoch times and mx datetimes, as well as the > converter stuff. I agree that datetime is the cleanest approach. Always, better to choose standard libraries than 3rd party ones. > > The new plot_date signature would be > > def plot_date(self, d, y, fmt='bo', **kwargs): > > where d would be an array of floats (no converter) and the floats > would be the number of days since 1,1,1 (Gregorian calendar). The > supported date range would be datetime.min to datetime.max (years 0001 > - 9999). Actually, MATLAB adopts the same approach using floats for date and time. There, the epoch is 0000/00/00. The datenum and datestr functions provide the conversion between floats and strings. > > The dates module would provide some helper functions so that you could > use to build date arrays from datetime and timedelta instances. It > not be too hard to add some helper functions to convert existing > epoch, mx, or datetime arrays to the required array of days floats. > > timezones, including timezones other than the local one, would be > supported. Ie, if you are a financial guru in California, you could > work with Eastern time zone stock quotes or Central time zone pork > belly quotes. daylight savings time, etc, would be handled by the > datetime module. I have developed similar functions to convert an array of date or datetime to array of numbers. To avoid imprecision of floating points, I used seconds since 1900/1/1 without considering time zone. For my own domain, hydrologic modeling, I am rarely concerned about time zone. Based on my experience, I noticed the following things. The function names to_ordinalf and from_ordinalf are difficult to remember. How about just time2num and num2time? In addition, how about modifying the functions to handle an array of numbers or datetimes directly using map function? And the from_ordinalf function will produce an error message if date object, not datetime object, is tossed. I also recommend to provide strftime and isoformat functions to handle array of floating points directly. Thanks for your effort. Daehyok Shin |