On Wed, Aug 19, 2015 at 1:23 PM, Chris Barker <[email protected]> wrote:
> IIUC, PEP 500 essentially says essentially anything that datetime does can > be delegated to a tzinfo object. Which reduces the datetime object to a > simple container of a datetime stamp: > > years, months, days, hours, min, sec, microsec. > > No, it is more than that: you forgot the tzinfo. :-) However without tzinfo, it is a container plus the naive arithmetic, plus simple formatting and parsing, plus conversions to and from various other forms - timetuple, timestamp, etc. The 5000+ lines of the datetime library code are not going anywhere with PEP 500. > As the current implementation has a way to add on tzinfo object, it is a > way forward to make them all-powerful, to add arbitrary functionality > without changing the way an existing code will work -- but it it the only > or best way? > IMO, this is the most straightforward way. The tzinfo object implementation is where you ultimately have the information you need to implement the timeline arithmetics. To do that in datetime object, you need a way to communicate the information from the tzinfo object to datetime. The current interface that consists of .utcoffset() .dst() and optionally .fromutc() methods becomes your bottleneck because a well-written __datetime_sub__ method can get you the result faster than the two calls to .utcoffset(). Look at the typical implementation of the C mktime() function: < https://github.com/lattera/glibc/blob/master/time/mktime.c#L343>. The reason it is so ridiculously complicated is that it has a needle hole view of the timezone data. You have a similar situation when your needle hole is the tzinfo interface. You have to forgo all the simplifications that are possible when you know the specifics of your timezone. Even if your timezone is identical to UTC, you still end up adding and subtracting timedelta(0) on each arithmetic operation.
_______________________________________________ Datetime-SIG mailing list [email protected] https://mail.python.org/mailman/listinfo/datetime-sig The PSF Code of Conduct applies to this mailing list: https://www.python.org/psf/codeofconduct/
