Time since the epoch

George Russell ger@tzi.de
Tue, 11 Feb 2003 22:41:39 +0100


Peter Thiemann wrote:
> 
>     George> OK, what TimeExts does, I hope, is add the appropriate amount of the appropriate
>     George> time unit (whatever it is) directly, then rely on the CalendarTime conversions to
>     George> resolve any overflows.  This probably isn't very clear,
>     George> so I'll give some examples of what I think ought to
>     George> happen.
> 
> I see. You propose to always add the duration of the current
> entity. IE, a month rooted in January has 31 days, and a year rooted
> in a leap year has 366 days. How do you define subtraction, given that
> your addition is not monotonic and that you (probably) want addition
> and subtraction be inverses?
I would drop the requirement that addition and subtraction be inverse, and
use exactly the same procedure only with changes of sign.  So first adjust the date,
then roll.

> 
> Actually, you could equally well argue that you should always take the
> duration of the next following entity (in seconds, but I won't go into
> that detail). While this means that  (in a non-leap year)
> January 1 + 1 month = January 29
> it preserves monotonicity:
> January 31 + 1 month = February 28
> so that you could define subtraction (although at some expense).
[snip]
Well I don't see much point in arguing this at length, since this is one case where it doesn't
really matter what we do so long as we do something.   HOWEVER I will make some brief points
and then leave it to other Haskellers to argue about.

Here are some specific objections.
(1) Peter's notion of addition is odd.  I can't believe anyone but Peter would say that the date
1 month from 1st January is 29th January in a non-leap year, or 30th January in a leap year.
(2) Peter's notion of subtraction is worse.  True, it's
inverse to addition, but that's all it's good for.  For example, if you ask "What happens
if you subtract 1 month from 1st February?", then Peter's method gives you "4th January in a normal
year, or 3rd January in a leap year".  I can't believe if you were to ask someone on the street
"What date is 1 month before 1st February?" they would give you that answer.
(3) Both are fundamentally asymmetric.  What happens for example when you add (-1) months?
Do you subtract the length of the previous month?  This is nice and symmetrical.  Or do you
subtract the length of this month?  This is not symmetrical, but means that it is the same
as subtracting 1 month.

However there's an ever better objection which has just occurred to me.  Peter's notion of
subtraction is UNDEFINED.  For, what is 29th January MINUS 1 month?  As he says, in his system.

January 1 + 1 month = January 29

but of course it is also true that

December 29 + 1 month = January 29.

Even worse, December 30 + 1 month = January 30th, so you don't have monotonicity either.

So while I started typing this thinking it was a straight choice between Peter's monotonicity/invertibility
and the fact that my system corresponds better to natural usage, Peter doesn't even have 
monotonicity or invertibility.  So I think my method wins.  Nyaaa.