I was looking at "tsPlus" from here -
http://www.jsoftware.com/jwiki/Addons/types/datetime - and noticed that
(6{.1995 12 31) tsPlus 6{.0 6
returns
1995 7 1 0 0 0
instead of
1996 6 30 0 0 0
as I would expect.
I have a (very ugly) verb "TSAdd" that I believe is mostly correct:
TSAdd=: 4 : 0
NB. Still has bug: will give year 0.
NB.* TSAdd: add timestamp to relative timestamp (#years, months, days,
hours, mins, secs).
NB. in form Y M D h m s= years months days hours minutes seconds.
timebase=. 0 12 31 24 60 60 [ origin=. 1 1 1 0 0 0 [ maxdays=. 31 28 31
30 31 30 31 31 30 31 30 31
'x y'=. (-#timebase){.&.>x;<y NB. Pad w/lead 0s if short.
x=. x-origin*0~:*x
ds=. +/;(<timebase)#.&.>x;<y
sum=. origin+timebase#: ds
maxdays=. (28+isLeapYr {.sum) 1}maxdays
sum=. ((maxdays{~<:1{sum)<.2{sum) 2}sum
ds;sum NB. Sum in both seconds and in Y M D h m
s.
NB.EG (6!:0 '') TSAdd 10 15 NB. 10 min, 15 seconds from now.
NB.EG (6{.1999 12 31) TSAdd 6{.0 2 NB. 2 months after end of 1999.
)
--
Devon McCormick, CFA
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm