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

[REBOL] Re: Displaying AM / PM times

From: joel:neely:fedex at: 26-Aug-2001 17:08

Hi, John, john wrote:
> The code works fine, as lond as I enter it from the console or > point it to a specific piece of data. > > It doesn't work ( I am doing something that confuses it) when I > place it in a table trying to print elements of an array line. > The data in the line is correct in format, at least Excel > converts it ok. > > ;Here are some specific script that refers to one line of data > from the array including this row: > ;" > 4:56 5:01 5:07 5:17 5:27 5:30 5:35 > 5:43 5:52 5:57 6:05" >
If I read your email correctly, you're dealing with a "line of data" that is a string. In order to manipulate its content as TIME! values, you have to break it apart and convert the pieces to the appropriate type. Here are some test data...
>> stringline: "4:56 5:01 5:07 5:17 5:27 5:30 5:35"
== {4:56 5:01 5:07 5:17 5:27 5:30 5:35} ...and here's the function that Allen recommended...
>> nice-time: func [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] [ ] ...and here's one way to get them together:
>> foreach val parse stringline none [
[ print nice-time to-time val [ ] 4:56 AM 5:01 AM 5:07 AM 5:17 AM 5:27 AM 5:30 AM 5:35 AM The PARSE STRINGLINE NONE breaks the line into a block of strings (breaking on whitespace). The FOREACH steps VAL through those strings, and the body of the loop converts each one to a TIME! value which is pretty-printed. HTH! -jn- -- ------------------------------------------------------------ Programming languages: compact, powerful, simple ... Pick any two! joel'dot'neely'at'fedex'dot'com