Re: DT_DATE_TIME_DURATION usage

Eric Bezault <ericb-D6Qt/9opevxWk0Htik3J/[email protected]> Thu, 29 May 2008 09:12:25 +0200
Newsgroups gmane.comp.lang.eiffel.gobo.general
Message-ID <[email protected]>
Berend de Boer wrote:
>>>>>> "Eric" == Eric Bezault <ericb-D6Qt/9opevxWk0Htik3J/[email protected]> writes:
> 
>     Eric> ~~~~~~~~~~~~~~~~~~~ Let's consider that you have a duration of
>     Eric> 1 month, and you want to quarter of it. What should it be?
>     Eric> Well, I guess it depends on what you want to do with that
>     Eric> duration. If it's to be added to a date, then the result
>     Eric> depends on that date. In that case I would suggest turning the
>     Eric> duration into a definite duration (using `to_definite').
>     Eric> ~~~~~~~~~~~~~~~~~~~
> 
>     Eric> Indeed, one month to be added to 1 Feb 2007 is equivalent to
>     Eric> 28 days.  So a quarter of it will be 7 days. But when to be
>     Eric> added to 1 Jan 2007 it is equivalent to 31 days. And a quarter
>     Eric> of it will be 7 days and 18 hours.
> 
> Hmm, maybe my original question wasn't precise enough then.
> 
> I have two dates, a begin and end date. I want to divide the duration
> between these days in X divisions. For my purposes it would be enough
> to know the number of seconds between these two dates. I don't care
> about leap seconds for this application.

In that case, use the begin date for the argument of `to_definite'.

> I can get a DT_DATE_TIME_DURATION between these two dates of course, but
> I'm still unsure what to_definite does with the date I pass.

If you use begin_date.duration (end_date), you are lucky because
the result is already definite (the month and year parts are zero).

But if it were not, let me use my example above again to explain
what `definite' means. If my begin date is 1 Feb 2007 and the
duration is 1 month and 1 day, then the definite duration will
be 0 month and 29 days. If the begin date is 1 Jan 2007, then
the definite duration will be 0 month and 32 days.

> Is there any other way to get the seconds between these two dates?
> Perhaps DT_DATE_TIME should have an epoch_time feature which returns the
> number of seconds, that would make such calculations far more trivial.

Or you will get overflow because the number of seconds is too large
to fit into an integer.

-- 
Eric Bezault
mailto:ericb-D6Qt/9opevxWk0Htik3J/[email protected]
http://www.gobosoft.com