fifth-postulate / julian

Date and time library for Prolog
The Unlicense
27 stars 3 forks source link

two digit years #10

Open Anniepoo opened 7 years ago

Anniepoo commented 7 years ago

Years like '79', to be interpreted as 1979, are not handled correctly.

?- form_time(79-03-15,D). D = datetime(-650014, _2817026), _2817026 in 0..86399999999999.

I'm not sure what the fix is.

In some theoretical sense, we could have y2k(40) that would constrain us to interpret years between 40 and 99 as 1940..1999 and years 0..39 as 2000..2039

But obviously I'm here because I naively passed a year in. It'd be nice behavior if form_time just 'did the right thing' - if some y2k constraint was a default. And then we have to have some explicit dont_fix_y2k so the poor soul recording Roman history has a workaround.

But then we have a set of soft constraints

  1. If the year is outside the y2k range, take it as is
  2. If the user supplied a y2k range, use that
  3. otherwise, if the user said dont_fix_y2k, treat as is
  4. otherwise, use the default y2k range

And then there's the mess of asking what it means to have dates before the Gregorian epoch.

As far as implementation, that's also ugly, as everything's a constraint, not a production. Maybe the form Y-M-D could accept Y as yr(79) and do some mapping? or instead of my y2k constraint, have y2k(79,40)-M-D ?

That's ugly but works. No real elegant solution.

Anniepoo commented 7 years ago

I guess a more constraints way is to make 79 map to Y #= N * 100 + 79

Julien has poor separation of parsing and representation concerns from true time arithmetic concerns (of course, it was only intended to handle the latter).