Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

[REBOL] Re: how do I get ampm format for time?

From: jeff:rebol at: 19-Jan-2001 11:39

Howdy, Bo:
> Before anyone else pipes in, I just realized I used a few > extra characters. If I'm gonna try to do this succinctly, > I might as well go all out, eh? ;-) > > time-ampm: func[dt][join dt // 12:0[pick"AP"dt < 12:0"M"]] > > I don't recommend doing this for readability's sake, but it > does show the smartness of the language parser. And I did > challenge someone to make it shorter... > > -Bo
Sweet and short, but it gives unusual results around noon and midnight:
>> time-ampm 12:00
== "0:00PM"
>> time-ampm 24:00
== "0:00PM"
>> time-ampm :59
== "0:59AM"
>> time-ampm 12:59
== "0:59PM It would be nice to be able to distinguish 12:00 AM from 12:00 PM and to have the typical digital clock format which includes the hour 12-- so, a bit longer but well behaved around lunch and the witching hour: time-ampm: func [dt [time!] /dd/merid][ merid: pick [PM AM] found? all [24:0 > dt dt >= 12:0 ] reduce [(dd: dt // 12:0) + pick [12:0 0] 1:0 > dd merid] ]
>> time-ampm 12:0
== [12:00 PM]
>> time-ampm 24:0
== [12:00 AM]
>> time-ampm 12:59
== [12:59 PM]
>> time-ampm :59
== [12:59 AM] -jeff