[Cosmo-dev] Re: [commits-cosmo] (travis) [4317] Duration serialization functions.

Travis Vachon travis at osafoundation.org
Sat May 5 09:10:06 PDT 2007


Good call. Darn pbr.

Thanks,

Travis

On May 4, 2007, at 10:49 PM, Bobby Rullo wrote:

> 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
>
> _______________________________________________
> cosmo-dev mailing list
> cosmo-dev at lists.osafoundation.org
> http://lists.osafoundation.org/mailman/listinfo/cosmo-dev



More information about the cosmo-dev mailing list