I still like my own "TSAdd", ugly as it looks:
2005 12 31 0 0 0 tsPlus 6{.0 6
2006 7 1 0 0 0
2005 12 31 0 0 0 tsPlus 6{.0 2
2006 3 3 0 0 0
NB. versus
>{:2005 12 31 0 0 0 TSAdd 6{.0 6
2006 6 30 0 0 0
>{:2005 12 31 0 0 0 TSAdd 6{.0 2
2006 2 28 0 0 0
On Wed, Feb 19, 2014 at 4:47 PM, Ric Sherlock <[email protected]> wrote:
> Thanks Devon, I can confirm this bug.
>
> tsPlus is currently defined as:
>
> tsPlus=: [: toDateTime@toDayNo (6&{.@[ + adjustYrMth@(_6&{.@]))"1 f.
> where adjustYrMth is
> adjustYrMth=. 2&}. ,~ [: ]&.:(0 12&#.) 2&{.
>
> I think the issue can be resolved by moving adjustYrMth to after the
> addition?
>
> tsPlus=: [: toDateTime@toDayNo adjustYrMth@(6&{.@[ + _6&{.@])"1 f.
>
> 1995 12 28 tsPlus 6 0 0 0 0
>
> 1996 6 28 0 0 0
>
>
> On Thu, Feb 20, 2014 at 9:06 AM, Devon McCormick <[email protected]>
> wrote:
>
> > 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
> >
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
>
--
Devon McCormick, CFA
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm