Download Reference Manual
The Developer's Library for D
About Wiki Forums Source Search Contact

Ticket #778 (closed defect: fixed)

Opened 12 years ago

Last modified 12 years ago

DateTime doesn't support dates prior to epoch, may crash

Reported by: Deewiant Assigned to: schveiguy
Priority: major Milestone: 0.99.4
Component: Core Functionality Version: trunk
Keywords: Cc:


DateTime? needs a mechanism to support dates prior to the epoch, 0001-01-01. Consider the following snippet:

DateTime dt;
dt += TimeSpan.hours(-3);

Now dt's date remains at 0001-01-01 and the time is an interesting "-3:00". The ideal result would be -0001-12-31 21:00). In any case, the time shouldn't be left at an erroneous value.

The very real case in which this applies is when DateTime? has only a time component, which you want to perform arithmetic on---say, convert from one timezone to another. Given a time of "00:00" with a timezone of "+03:00" which is to be converted to UTC, the result is as above. A change in the day should be indicated somehow, and the time itself should of course be correct.

The following case is even worse: any access to dt.month will crash the program due to an ArrayBoundsException? in DateTime?.splitDate:

DateTime dt;
dt = dt.addMonths(-3);

Change History

11/26/07 17:19:06 changed by schveiguy

  • status changed from new to assigned.

Will work on changes to make negative times possible.

12/10/07 05:47:50 changed by schveiguy

Note that Time (used to be DateTime?) no longer has date components. However, these concerns are still valid for the Calendar classes.

12/20/07 18:10:43 changed by schveiguy

  • status changed from assigned to closed.
  • resolution set to fixed.

Gregorian now supports dates prior to 1 A.D. properly.

12/20/07 20:26:41 changed by kris

  • milestone set to 0.99.4.