summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_datetime.py
Commit message (Collapse)AuthorAgeFilesLines
* SF bug #761337: datetime.strftime fails on trivial format stringRaymond Hettinger2003-06-271-0/+1
| | | | | | | | | | | | | | The interning of short strings violates the refcnt==1 assumption for _PyString_Resize(). A simple fix is to boost the initial value of "totalnew" by 1. Combined with an NULL argument to PyString_FromStringAndSize(), this assures that resulting format string is not interned. This will remain true even if the implementation of PyString_FromStringAndSize() changes because only the uninitialized strings that can be interned are those of zero length. Added a test case.
* datetime.timedelta is now subclassable in Python. The new test showsTim Peters2003-05-171-0/+31
| | | | | | | | one good use: a subclass adding a method to express the duration as a number of hours (or minutes, or whatever else you want to add). The native breakdown into days+seconds+us is often clumsy. Incidentally moved a large chunk of object-initialization code closer to the top of the file, to avoid worse forward-reference trickery.
* datetime.datetime and datetime.time can now be subclassed in Python. Brr.Tim Peters2003-05-171-31/+131
|
* test_subclass_date(): Beefed this up, to check that new instanceTim Peters2003-05-171-2/+28
| | | | | | | attributes and methods work, that new arguments can be passed to the constructor, and that inherited methods and attrs still work. Added XXX comments about what to do when datetime becomes usably subclassable too (it's not yet).
* The date class is now properly subclassable. (SF bug #720908)Guido van Rossum2003-04-141-0/+6
| | | | | (This is only the tip of the iceberg; the time and datetime classes need the same treatment.)
* Whitespace normalization.Tim Peters2003-02-191-11/+11
|
* The Python implementation of datetime was changed in ways that no longerTim Peters2003-02-081-31/+10
| | | | | | | tickle the 2.2.2 __cmp__ bug test_datetime used to tickle, so the workarounds for that bug no longer make sense in the test suite (which I'm still trying to keep as closely in synch as possible with Zope3's version).
* Comparison for timedelta, time, date and datetime objects: __eq__ andTim Peters2003-02-071-18/+68
| | | | | | | | | | | | | | | | | __ne__ no longer complain if they don't know how to compare to the other thing. If no meaningful way to compare is known, saying "not equal" is sensible. This allows things like if adatetime in some_sequence: and somedict[adatetime] = whatever to work as expected even if some_sequence contains non-datetime objects, or somedict non-datetime keys, because they only call __eq__. It still complains (raises TypeError) for mixed-type comparisons in contexts that require a total ordering, such as list.sort(), use as a key in a BTree-based data structure, and cmp().
* Merge the test part of the below checkin to the sandbox and Zope3, soGuido van Rossum2003-02-071-0/+8
| | | | | | | | | | | | the tests will remain in sync: """ Tres discovered a weird bug when a datetime is pickled, caused by the shadowing of __year, __month, __day and the use of proxies. Here's a quick fix and a quick unit test. I don't quite understand why this wasn't caught by the pickling unit tests. """
* SF bug 680864: test_datetime fails for non-unix epochTim Peters2003-02-061-12/+11
| | | | | | Apparently MAC OS 9 doesn't have POSIX-conforming timestamps. A test fails as a result, but at least for this specific test it's easy enough to get the POSIX epoch out of it.
* Build pickler_choices list in a lazier way.Tim Peters2003-02-051-16/+5
|
* cPickle now implements enough of protocol 2 to enable allGuido van Rossum2003-02-031-3/+3
| | | | cross-pickling tests.
* There's no good reason for datetime objects to expose __getstate__()Tim Peters2003-02-011-12/+0
| | | | | | anymore either, so don't. This also allows to get rid of obscure code making __getnewargs__ identical to __getstate__ (hmm ... hope there wasn't more to this than I realize!).
* Changed the tests to stop using __setstate__(). __setstate__() noTim Peters2003-01-311-65/+31
| | | | | | longer needs to be public, and shoudn't be public because all datetime objects are immutable. The Python implementation has changed accordingly, but still need to change the C implementation.
* Change the approach to pickling to use __reduce__ everywhere. MostGuido van Rossum2003-01-301-53/+49
| | | | | | | classes have a __reduce__ that returns (self.__class__, self.__getstate__()). tzinfo.__reduce__() is a bit smarter, calling __getinitargs__ and __getstate__ if they exist, and falling back to __dict__ if it exists and isn't empty.
* date and datetime comparison: when we don't know how toTim Peters2003-01-241-0/+38
| | | | | | | | | | | | | | | | | | | | | | | | compare against "the other" argument, we raise TypeError, in order to prevent comparison from falling back to the default (and worse than useless, in this case) comparison by object address. That's fine so far as it goes, but leaves no way for another date/datetime object to make itself comparable to our objects. For example, it leaves Marc-Andre no way to teach mxDateTime dates how to compare against Python dates. Discussion on Python-Dev raised a number of impractical ideas, and the simple one implemented here: when we don't know how to compare against "the other" argument, we raise TypeError *unless* the other object has a timetuple attr. In that case, we return NotImplemented instead, and Python will give the other object a shot at handling the comparison then. Note that comparisons of time and timedelta objects still suffer the original problem, though.
* SF bug 660872: datetimetz constructors behave counterintuitively (2.3a1).Tim Peters2003-01-231-1/+15
| | | | | | This gives much the same treatment to datetime.fromtimestamp(stamp, tz) as the last batch of checkins gave to datetime.now(tz): do "the obvious" thing with the tz argument instead of a senseless thing.
* Reimplemented datetime.now() to be useful.Tim Peters2003-01-231-2/+20
|
* Bringing the code and test suite into line with doc and NEWS changesTim Peters2003-01-231-28/+90
| | | | | | | | | | | | | | | | | | | | checked in two days agao: Refactoring of, and new rules for, dt.astimezone(tz). dt must be aware now, and tz.utcoffset() and tz.dst() must not return None. The old dt.astimezone(None) no longer works to change an aware datetime into a naive datetime; use dt.replace(tzinfo=None) instead. The tzinfo base class now supplies a new fromutc(self, dt) method, and datetime.astimezone(tz) invokes tz.fromutc(). The default implementation of fromutc() reproduces the same results as the old astimezone() implementation, but tzinfo subclasses can override fromutc() if the default implementation isn't strong enough to get the correct results in all cases (for example, this may be necessary if a tzinfo subclass models a time zone whose "standard offset" (wrt UTC) changed in some year(s), or in some variations of double-daylight time -- the creativity of time zone politics can't be captured in a single default implementation).
* New rule for tzinfo subclasses handling both standard and daylight time:Tim Peters2003-01-201-20/+27
| | | | | | | | | | | | When daylight time ends, an hour repeats on the local clock (for example, in US Eastern, the clock jumps from 1:59 back to 1:00 again). Times in the repeated hour are ambiguous. A tzinfo subclass that wants to play with astimezone() needs to treat times in the repeated hour as being standard time. astimezone() previously required that such times be treated as daylight time. There seems no killer argument either way, but Guido wants the standard-time version, and it does seem easier the new way to code both American (local-time based) and European (UTC-based) switch rules, and the astimezone() implementation is simpler.
* Got rid of the internal datetimetz type.Tim Peters2003-01-111-1/+1
|
* Got rid of the timetz type entirely. This was a bit trickier than ITim Peters2003-01-101-1/+1
| | | | | | | hoped it would be, but not too bad. A test had to change: time.__setstate__() can no longer add a non-None tzinfo member to a time object that didn't already have one, since storage for a tzinfo member doesn't exist in that case.
* Utterly minimal changes to collapse datetimetz into datetime, and timetzTim Peters2003-01-081-68/+89
| | | | | | | | | into time. This is little more than *exporting* the datetimetz object under the name "datetime", and similarly for timetz. A good implementation of this change requires more work, but this is fully functional if you don't stare too hard at the internals (e.g., right now a type named "datetime" shows up as a base class of the type named "datetime"). The docs also need extensive revision, not part of this checkin.
* A new implementation of astimezone() that does what we agreed on in allTim Peters2003-01-041-16/+33
| | | | | | cases, plus even tougher tests of that. This implementation follows the correctness proof very closely, and should also be quicker (yes, I wrote the proof before the code, and the code proves the proof <wink>).
* The tzinfo methods utcoffset() and dst() must return a timedelta objectTim Peters2003-01-021-32/+40
| | | | | | (or None) now. In 2.3a1 they could also return an int or long, but that was an unhelpfully redundant leftover from an earlier version wherein they couldn't return a timedelta. TOOWTDI.
* astimezone() internals: if utcoffset() returns a duration, complain ifTim Peters2003-01-021-0/+17
| | | | dst() returns None (instead of treating that as 0).
* A quicker astimezone() implementation, rehabilitating an earlierTim Peters2003-01-011-0/+25
| | | | | | | | | | | | | | | | | | | suggestion from Guido, along with a formal correctness proof of the trickiest bit. The intricacy of the proof reveals how delicate this is, but also how robust the conclusion: correctness doesn't rely on dst() returning +- one hour (not all real time zones do!), it only relies on: 1. That dst() returns a (any) non-zero value if and only if daylight time is in effect. and 2. That the tzinfo subclass implements a consistent notion of time zone. The meaning of "consistent" was a hidden assumption, which is now an explicit requirement in the docs. Alas, it's an unverifiable (by the datetime implementation) requirement, but so it goes.
* The failure of the last-second addition to the timezone coversion test isTim Peters2003-01-011-4/+12
| | | | | | understood now: it can't work. Added comments explaining why (it's "the usual"-- unrepresentable hours in local time --but in a slightly different guise).
* A new, and much hairier, implementation of astimezone(), building onTim Peters2002-12-311-86/+86
| | | | | | | | | | | | | | | | | | | | | | | | | | an idea from Guido. This restores that the datetime implementation never passes a datetime d to a tzinfo method unless d.tzinfo is the tzinfo instance whose method is being called. That in turn allows enormous simplifications in user-written tzinfo classes (see the Python sandbox US.py and EU.py for fully fleshed-out examples). d.astimezone(tz) also raises ValueError now if d lands in the one hour of the year that can't be expressed in tz (this can happen iff tz models both standard and daylight time). That it used to return a nonsense result always ate at me, and it turned out that it seemed impossible to force a consistent nonsense result under the new implementation (which doesn't know anything about how tzinfo classes implement their methods -- it can only infer properties indirectly). Guido doesn't like this -- expect it to change. New tests of conversion between adjacent DST-aware timezones don't pass yet, and are commented out. Running the datetime tests in a loop under a debug build leaks 9 references per test run, but I don't believe the datetime code is the cause (it didn't leak the last time I changed the C code, and the leak is the same if I disable all the tests that invoke the only function that changed here). I'll pursue that next.
* A step on the way to making tzinfo classes writable by mortals: get ridTim Peters2002-12-301-17/+38
| | | | | | | of the timetz case. A tzinfo method will always see a datetimetz arg, or None, now. In the former case, it's still possible that it will get a datetimetz argument belonging to a different timezone. That will get fixed next.
* Added tests that conversion to our own timezone is always an identity,Tim Peters2002-12-301-0/+13
| | | | | and that conversion to "timezone" None is the same as stripping the tzinfo member.
* Beefed up the timezone conversion test by adding a phony UTC zone that'sTim Peters2002-12-301-67/+81
| | | | | west of the US zones getting converted, and also by using Eastern "as if" it were UTC (wrt Pacific), and vice versa.
* A start at non-trivial (== DST-aware) tests of timezone conversion.Tim Peters2002-12-291-0/+152
| | | | | | | Guido has in mind an easier way for users to code this stuff, but the only tests we have now are for fixed-offset tzinfo classes, and this stuff is extremely delicate in the endcases (read the new test code for why: there are holes in time <wink>).
* Make comparison and subtraction of aware objects ignore tzinfo if theTim Peters2002-12-271-8/+86
| | | | | | operands have identical tzinfo members (meaning object identity -- "is"). I misunderstood the intent here, reading wrong conclusion into conflicting clues.
* Added tests to ensure that timetz comparison, and datetimetzTim Peters2002-12-261-9/+67
| | | | | | | | | | | subtraction, work as documented. In the Python implementation, they weren't calling utcoffset() if both operands had the same tzinfo object. That's fine if it so happens that the shared tzinfo object returns a fixed offset (independent of operand), but can give wrong results if that's not so, and the latter obtains in a tzinfo subclass instance trying to model both standard and daylight times. The C implementation was already doing this "correctly", so we're just adding tests to verify it.
* Implemented datetime.astimezone() and datetimetz.astimezone().Tim Peters2002-12-251-0/+53
|
* Whitespace normalization.Tim Peters2002-12-241-1/+1
|
* Implemented .replace() methods for date, datetime, datetimetz, time andTim Peters2002-12-241-0/+150
| | | | timetz.
* I give up: unless I write my own strftime by hand, datetime just can'tTim Peters2002-12-221-0/+6
| | | | | | be trusted with years before 1900, so now we raise ValueError if a date or datetime or datetimetz .strftime() method is called with a year before 1900.
* Implemented a Wiki suggestion:Tim Peters2002-12-221-71/+118
| | | | | | | | | | | | {timetz,datetimetz}.{utcoffset,dst}() now return a timedelta (or None) instead of an int (or None). tzinfo.{utcoffset,dst)() can now return a timedelta (or an int, or None). Curiously, this was much easier to do in the C implementation than in the Python implementation (which lives in the Zope3 code tree) -- the C code already had lots of hair to extract C ints from offset objects, and used C ints internally.
* Added test to ensure that non-string result from dst() raises TypeError.Tim Peters2002-12-211-0/+6
|
* Changes sufficient so that pickles written by the Python implementationTim Peters2002-12-211-9/+15
| | | | can be read by the C implementation. I don't really understand this.
* format_utcoffset(): The natural type of the buflen arg is size_t, soTim Peters2002-12-201-9/+16
| | | | | | | | | | used that. wrap_strftime(): Removed the most irritating uses of buf. TestDate.test_ordinal_conversions(): The C implementation is fast enough that we can afford to check the endpoints of every year. Also added tm_yday tests at the endpoints.
* Made this a little more compatible w/ the sandbox version, which isTim Peters2002-12-161-2/+2
| | | | still needed to test the Python implementatino.
* datetime escapes the sandbox. The Windows build is all set. I leave itTim Peters2002-12-161-0/+2128
to others to argue about how to build it on other platforms (on Windows it's in its own DLL).