[Cosmo-dev] Re: [commits-cosmo] (travis) [4317] Duration
serialization functions.
Bobby Rullo
br at osafoundation.org
Fri May 4 22:49:46 PDT 2007
Travis,
Is this function supposed to return the difference between two dates,
in the format of a Duration object?
One potential problem I see is that startDate, which is just an alias
to dt1 which is one of the arguments gets trampled on. You probably
want to clone that first...
bobby
On May 3, 2007, at 2:14 PM, svncheckin at osafoundation.org wrote:
>>
> -cosmo.datetime.getIso8601Duration = function(dt1, dt2){
> +cosmo.datetime.getDuration = function getDuration(dt1, dt2){
> + var dur = {}
> + var startDate = dt1;
> + with(dojo.date.dateParts){
> + dur.year = cosmo.datetime.Date.diff(YEAR, startDate, dt2);
> + startDate = startDate.add(YEAR, dur.year);
> + dur.month = cosmo.datetime.Date.diff(MONTH, startDate, dt2);
> + startDate = startDate.add(MONTH, dur.month);
> + dur.day = cosmo.datetime.Date.diff(DAY, startDate, dt2);
> + startDate = startDate.add(DAY, dur.day);
> + dur.hour = cosmo.datetime.Date.diff(HOUR, startDate, dt2);
> + startDate = startDate.add(HOUR, dur.hour);
> + dur.minute = cosmo.datetime.Date.diff(MINUTE, startDate,
> dt2);
> + startDate = startDate.add(MINUTE, dur.minute);
> + dur.second = cosmo.datetime.Date.diff(SECOND, startDate,
> dt2);
> + startDate = startDate.add(SECOND, dur.second);
> + }
> + return dur;
> +}
>
> - r
More information about the cosmo-dev
mailing list