On Sat, Feb 19, 2011 at 1:35 AM, Ric Sherlock <tikk...@gmail.com> wrote:

> I'm interested in suggested improvements or alternative approaches.
>
> NB.*sayDiffNow v Phrase describing "length of time ago"
> NB. eg: sayDiffNow 0.02
> NB. eg: sayDiffNow (6!:0'') daysDiff 2011 2 19 9 30 4.24
> NB. y is: numeric number of days before "now" (day zero)
> sayDiffNow=: (3 : 0)"0
>  getidx=. 0 1r24 2r24 1 2 14 31 _&({.@I.@:>)
>  msg=.'in the future';'less than an hour ago';' hour ago';' hours ago'
>  msg=. msg,' day ago';' days ago';' weeks ago';'more than a month ago'
>  msg=. msg {::~ getidx y
>  time=. ,":<. empty`empty`(24&*)`(24&*)`]`]`(%&7)`empty@.getidx y
>  time,msg
> )
>

I would be tempted to use
   getidx=. (0 1r24 2r24 1 2 14 31 -9!:18'')&I.

I would also be tempted to use sprintf&>~ to build the message (putting %d
into the strings that need numeric arguments), and getting rid of "0 in the
function declaration.  Then, rather than using a gerund, I could just select
a multiplier.

-- 
Raul
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to