Home   Archive   Permalink



Why difference doesn't work with time values?

It would be nice if difference work with time! values.
    
>> difference 10-1-1/12:14:10 10-1-1/12:06:10
== 0:08
    
>> difference 12:14:10 12:06:10
** Script Error: difference expected series...


posted by:   Endo     7-Jul-2010/10:19:10-7:00



>> 12:14:10 - 12:06:10
== 0:08
    
is enough I guess :)

posted by:   Endo     7-Jul-2010/10:24:47-7:00



"help difference" show that it's only intended to work with series, bitset, and date. Honestly not sure why it even works with date. I've only ever used it to compare series of data - I never thought of it as a subtraction operator:
    
USAGE:
     DIFFERENCE set1 set2 /case /skip size
    
DESCRIPTION:
     Return the difference of two data sets.
     DIFFERENCE is a native value.
    
ARGUMENTS:
     set1 -- First data set (Type: series bitset date)
     set2 -- Second data set (Type: series bitset date)
    
REFINEMENTS:
     /case -- Uses case-sensitive comparison.
     /skip -- Treat the series as records of fixed size
         size -- (Type: integer)

posted by:   Nick     7-Jul-2010/23:32:03-7:00



date1: 8-jul-2010/12:14:10
date2: 7-jul-2010/12:06:10
    
(to-time second parse form date1 "/") - (to-time second parse form date2 "/")
(to-date first parse form date1 "/") - (to-date first parse form date2 "/")

posted by:   Nick     7-Jul-2010/23:33:33-7:00



There is some strangeness about subtract operator on datetime values.
    
>> subtract 1:2:3 1:1:1
== 0:01:02 ;this is OK
    
>> subtract 2010-05-02 2010-05-01
== 1 ;OK
    
>> subtract 2010-05-02/1:2:3 2010-05-01
== 1 ;time part disappeared?
    
>> subtract 2010-05-02/1:2:3 2010-05-01/1:1:1
== 1 ;time parts disappeared?
    
>> 2010-05-02/1:2:3 - 2010-05-01/1:1:1
== 1 ;time part disappeared? *** WHY?
    
>> 1:2:3 - 1:1:1
== 0:01:02 ;OK
    
>> difference 2010-05-02/1:2:3 2010-05-01/1:1:1
== 24:01:02 ;always gives diff. as time
    
>> difference 2010-05-02 2010-05-01
== 24:00 ;same as above
    
>> difference 1:2:3 1:1:1
== error (doesn't work with times)
    
This weird one is marked as ***
Which means we should always consider date and time values separately.

posted by:   Endo     8-Jul-2010/3:08:08-7:00



Yes, that's why I separated the date and time values with parse, in the example above. I would categorize that as a "gotcha" :)

posted by:   Nick     8-Jul-2010/11:38:57-7:00



Yes, but we should consider that if time difference is negative, then we should date diff. minus 1.
    
Or we can use this, if we have a base date:
    
>> add 1970-1-1/0:0:0 difference 2010-05-1/1:2:3 2010-05-01/2:1:1
== 31-Dec-1969/23:01:02


posted by:   Endo     9-Jul-2010/10:59:59-7:00