[REBOL] Re: How to...? Convert Date of Birth to Age
From: jan:skibinski:sympatico:ca at: 25-Oct-2002 21:01
Since there are already several proposals re dates difference
I am teasing with one more. Postconditions say it all.
Jan
=========================================
USAGE:
TRIPLET date2 date1
DESCRIPTION:
A triplet of average values [years months days]
representing a difference beteen two dates.
To be used for information, not for arithmetics.
TRIPLET is a function value.
ARGUMENTS:
date2 -- (Type: date)
date1 -- (Type: date)
POSTCONDITIONS:
[(total-days? result) == abs (date2 - date1)]
[result/1 >= 0]
[(result/2 >= 0) and (result/2 <= 366)]
[(result/3 >= 0) and (result/3 <= 31)]
=============================================
Pick up any random date y1....
No matter what your choice is the results will be always
identical with those below. I just used 'to-integer for truncating
but the algorithm could be improved upon by using a combination
of careful rounding and truncating.
>> triplet y1 (y1 - 0)
== [0 0 0]
>> triplet y1 (y1 - 1)
== [0 0 1]
>> triplet y1 (y1 + 1)
== [0 0 1]
>> triplet y1 (y1 + 30)
== [0 0 30]
>> triplet y1 (y1 + 31)
== [0 1 1]
>> triplet y1 (y1 + 60)
== [0 1 30]
>> triplet y1 (y1 + 61)
== [0 2 1]
>> triplet y1 (y1 + 365)
== [0 11 31]
>> triplet y1 (y1 + 366)
== [1 0 1]