[REBOL] Re: Displaying AM / PM times
From: joel:neely:fedex at: 30-Aug-2001 17:45
Hi, John,
john wrote:
> I have a REBOL file I am using that presents bus schedules in a format
> readable for the blind.
> The data is dumped into an ASCII array, I read it by line and would like to
> modify the line to include AM or PM before REBOL places the elements into
> the HTML table.
>
> I have sniped the code to reflect what is done with one single line.:
>
> This is what the line looks like and it is tab delimited:
>
> 7:14 7:17 7:23 7:26 7:32 7:40 7:43 7:47 7:54 8:03 8:08
8:16 8:26
> How can I change the data in d7 to read AM/PM before it goes to the
> table, I need to retain the tabs?
>
The key is to turn the tab-delimited line into a block of
strings, each of which can be converted to a TIME! value
for submission to the time formatting function.
Using your definition of "nice time" formatting, I whomped
up the following demo (pretending that D7 was read from a
file) in a source file named timeform.r ...
REBOL []
d7: {8:17^-10:26^-12:40^-14:47^-16:03}
nicetime: func [time [time!] /local am] [
time/3: 0
am: pick [" AM" " PM"] time < 12:00
if time >= 12:00 [time: time - 12:00]
if time/1 = 0 [time/1: 12]
rejoin [time am]
]
makerow: func [s [string!] /local row] [
row: copy {<tr bordercolor="lightblue" border="1"
bgcolor="white">}
foreach t parse s none [
append row rejoin [
"^/"
<td width="6%" align="center">
nicetime to-time t
</td>
]
]
rejoin [row "^/" </tr>]
]
makerow d7
...which produces the following output...
>> print do %timeform.r
<tr bordercolor="lightblue" border="1" bgcolor="white">
<td width="6%" align="center">8:17 AM</td>
<td width="6%" align="center">10:26 AM</td>
<td width="6%" align="center">12:40 PM</td>
<td width="6%" align="center">2:47 PM</td>
<td width="6%" align="center">4:03 PM</td>
</tr>
>>
HTH!
-jn-
--
------------------------------------------------------------
Programming languages: compact, powerful, simple ...
Pick any two!
joel'dot'neely'at'fedex'dot'com