[LEAPSECS] Lets get REAL about time.

Stephen Colebourne scolebourne at joda.org
Fri Jan 27 09:44:17 EST 2012


On 27 January 2012 13:58, Clive D.W. Feather <clive at davros.org> wrote:

> Stephen Colebourne said:

>>> Oh? When is a month from Monday coming? What day is 4 months after the last

>>> day of next month? What about the antepenultimate day of next month?

>>> Explain your working in each case.

>> Each of those three examples requires the day-of-week,

>

> The first does, but only because I didn't phrase it as "When is a month

> from 30th January?", which is what I meant.

>

>> The point of storing data in this form is that most queries of a date

>> are for year, month and day-of-month. Similarly, most sets/adds, like

>> 2012-01-31 + 1month require the year, month and day-of-month. In the

>> format above, those calculations are easy.

>

> Okay, all of those three (as amended in the first case) are of that form:

>

>    2012-01-30 + 1 month

>    2012-02-29 + 4 months

>    2012-02-27 + 4 months

>

> and let me add:

>

>    2011-02-28 + 1 year


OK, I mean easy in computation, you mean easy as in well-defined result.

JSR-310 currently has a resolver plugin that you can specify to
control the result.
http://threeten.sourceforge.net/apidocs-2011-01-07/javax/time/calendar/DateResolvers.html

The default is previous-valid:
2012-01-30 + 1 month = 2012-02-29
2012-02-29 + 4 months = 2012-06-29
2012-02-27 + 4 months = 2012-06-27
2012-02-29 + 1 year = 2013-02-28
2011-02-28 + 1 year = 2012-02-28

Stephen


More information about the LEAPSECS mailing list