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

On 19-Jan-2001/4:52:34-6:00, [EMAIL PROTECTED] wrote:
>"Rebol/Core User's Guide" (page 63) also gives the following example:
>
>print either now/time < 12:00 ["AM"]["PM"]
>
>This approach could be easily adapted to:
>
>time-ampm: func [dt] [either dt < 12:00 [return join dt "AM"][return join
>dt - 12:00 "PM"]]
>
>
>>> time-ampm 8:00
>== "8:00AM"
>
>>> time-ampm 18:00
>== "6:00PM"
>
>Hope this is helpful.
>
>Scott
>
>
>----- Original Message -----
>From: "Bob Racko" <[EMAIL PROTECTED]>
>To: <[EMAIL PROTECTED]>
>Sent: Friday, January 19, 2001 12:51 AM
>Subject: [REBOL] how do I get ampm format for time?
>
>
>>
>>
>> how do I format dates to am/pm format
>> like: "hh:mm pm EST"
>>
>> is there a more succinct way to write this?
>>
>> time-ampm: func [ dt ]
>> [ rejoin [
>>
>>                        ; handle  hh:mm part
>> ( replace ( copy/part (
>>   rejoin [
>>          (either dt/time < 10:00 [ "0" ] [ "" ])  ;  hh:mm vs [h]h:mm
>>           either dt/time > 12:59:59
>>           [ mold dt/time - 12:00 ]
>>           [ mold dt/time ]
>>          ]
>> ) 5 ) "00:" "12:" )   ; midnite-1am is special
>>
>>
>>                        ; handle " pm EST" parts
>> either  dt/time > 11:59:59
>>   [ " pm" ]
>>   [ " am" ]
>>
>> " EST"
>> ]]
>>
>> yes this does the job, perhaps a mold could be factored out
>> and some parens are not needed.  now the challenge
>> is to write something that handles the exceptions
>> with less code. this version allows coding by deletion
>> since the two parts hh:mm vs am/pm indicator
>> are treated separately and simply concatenated.
>>
>> --
>> To unsubscribe from this list, please send an email to
>> [EMAIL PROTECTED] with "unsubscribe" in the
>> subject, without the quotes.
>>
>
>-- 
>To unsubscribe from this list, please send an email to
>[EMAIL PROTECTED] with "unsubscribe" in the 
>subject, without the quotes.
>
-- 
                           Bohdan "Bo" Lechnowsky
                           REBOL  Adventure Guide
           REBOL Technologies 707-467-8000 (http://www.rebol.com)
       The Official Source for REBOL Books (http://www.REBOLpress.com)

-- 
To unsubscribe from this list, please send an email to
[EMAIL PROTECTED] with "unsubscribe" in the 
subject, without the quotes.

Reply via email to