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
)

   sayDiffNow _2 0 0.05 0.1 0.5 1 13 22 32
in the future
less than an hour ago
1 hour ago
2 hours ago
12 hours ago
1 day ago
13 days ago
3 weeks ago
more than a month ago
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to