[REBOL] Re: date/time subrtaction ?
From: dlhawley::home::com at: 16-Nov-2000 21:50
I'm a bit confused about subtraction of date/time objects. Part of the problem is that
there seem to be 3 types invloved here:
time
date
and what i'll call
date/time
The latter is returned by now and behaves differently from a date! object although
>> type? now
== date!
The difference is reflected in the following:
>> dt: now
== 16-Nov-2000/21:36:31-8:00
>> d: now/date
== 16-Nov-2000
>> type? d
== date!
>> type? dt
== date!
Now add 10 seconds to each:
>> dt + 0:00:10
== 16-Nov-2000/21:36:41-8:00
>> d + 0:00:10
** Script Error: Cannot use add on date! value.
** Where: d + 0:00:10
So d and dt are a bit different.
Now on to subtraction:
>> d2: dt + 1 ; add 1 day
== 17-Nov-2000/21:36:31-8:00
>> d2 - dt
== 1 ; OK, I can live with that
but:
>> d2: dt + 0:0:10 ; add 10 seconds
== 16-Nov-2000/21:36:41-8:00
>> d2 - d
== 0
I guess I sort of expected to see d2 - d == 0:0:10
Now back to the difference between date and date/time.
It is often nice to figure out date/times based on seconds from nidnight. Is there a
better method than the following:
midnight: now/date
midnight-and-3-hours: to-date rejoin [ n "/" v ]
I suppose that this might make sense:
midnight: to-date rejoin [ now/date "/" 0:0 ]
--
David L. Hawley D.L. Hawley and Associates 1.503.274.2242
Software Engineer [David--L--Hawley--computer--org]