The Wisdom of Time

Keith Wansbrough Keith.Wansbrough@cl.cam.ac.uk
Mon, 07 Jan 2002 12:43:36 +0000


> what is the wisdom behind representing a TimeDiff as a struct of year,
> month, week and so on, instead of simply the (fractional) number of
> seconds, or similar?

Firstly, I believe that the Time module is broken, and no one has yet
come up with a satisfactory design.

But the behaviour you describe is necessary.  Consider:

01-Jan-2002 plus 1 month = 01-Feb-2002
01-Feb-2002 plus 1 month = 01-Mar-2002
01-Mar-2002 plus 1 month = 01-Apr-2002
01-Apr-2002 plus 1 month = 01-May-2002

The first and third differences are 2678400 seconds, but the second is
2419200 and the fourth is 2592000.

The same is true for many other time differences.  If you want the
interval between two times, then simply subtract the seconds; but if
you want to compute things like "next week", "next month", "next
year", you need to have specific units for that.  (For "next week",
consider the impact of leap seconds...)

HTH.

--KW 8-)