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: gjones05:mail:orion at: 19-Jan-2001 18:57

Hi, Jeff, Bo, et al Sorry to beat a dead horse, but as Larry Wall has said, there's more than one way to do things (and apologies to Bertrand Meyer ;-). Jeff and others politely pointed out my programming-logic gaff from early this morning. However, being a REBOL newbie, I have really enjoyed seeing all the ways to tackle the problem (great way to learn the tricks of the language). I would normally be more than satisfied with Jeff's solution: 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] ] but I was bothered that I couldn't get the logic to be correct using few tricks without the code seeming to grow exponentially in comparison to Jeff's, with his neat tricks. I mulled on it this evening and came up with: time-ampm-mine: func [dt [time!]] [ either dt >= 12:0 [ join (either dt < 13:0 [dt] [dt - 12:0]) "PM" ][ join (either dt < 1:0 [dt + 12:0] [dt]) "AM"] ] It seems to work at all the "boundary" cases, but please yell if I overlooked something. Being curious as to the affect that the differences in sources would have on execution time, I set up a loop to iterate the functions 1 million times and measured times. On my 500 mhz (de)Celeron, my function averaged 22 to 23 seconds, and Jeff's averaged 38 to 40 seconds. I still prefer Jeff's because of the "beauty" of the tricks used. As always, this information and 35 cents may buy you a phone call. Cheers, Scott