[REBOL] Re: how do I get ampm format for time?
From: bobr:dprc at: 20-Jan-2001 14:46
At 06:57 PM 1/19/01 -0600, GS Jones wrote:
>Hi, Jeff, Bo, et al
>It seems to work at all the "boundary" cases, but please yell if I
nearly everyone missed something.
shall I grade all of us on a curve?
#1) I consider that most of you overlooked a biggie.
Succinct was chosen as a precise word.
It doesn't only mean small or fast or unreadable. (smile)
It particularly doesn't mean "change the spec". It doesn't matter how fast
you make it if I must insert an intermediate function to convert what you
wrote into what would function as a drop-in replacement. You would have to
benchmark the intermediate too.
I used the word named 'dt (vs tm) as an argument in my example for a
reason. I also did not restrict the argument type for a reason. I was
passing date!s (not time!s) into it. Specifically I was passing structures
that would have a /time path or refinement to them. These were not just
time paths to things I made up, they had to work with standard rebol return
values that had a /time refinement.
In some cases I made a /local dt and copied your argument to the local as in
myampm: func [ adt /local dt ] [ dt: adt/time
... <your code here>
in order to avoid the intermediate function call overhead.
Here are test cases derived from actual working sections
of the code where the function is used.
time-ampm modified? %user.r
time-ampm ( oo: make object! [ time: now ] )
#2) most of you did not get the fact that the result was to be fixed width
(zero padded on the left) -- the clue was in the comment
; hh:mm vs [h]h:mm
This one turned out to be less important as the system I was trying to
mimic [remember my reason for starting the "How do I thread(s)" ???
] said fixed width in the spec but in implementation [reality] was
variable width and not 0 padded!
this one has a boundary case which wrecks even my own code.
#3) what about being able to get only what you are interested in?
>this version allows coding by deletion
>since the two parts ...
However, This part of the challenge seems to have been ignored.
In the area of potential refinements, I saw very little in the replies that
could be easily tweaked return the two separate values (AM PM vs 12
hrfmt). I guess it was the excitement of the hunt.
so here you also have a lesson in "coupling and cohesion". RT is to be
congratulated in the cohesion of the base date!time! refinements. I will
let you each decide how badly you sacrificed coupling in the interest of
beating a benchmark.
Overall, I appreciate the effort and
thanks for your participation.
Most of you figured out that there was little I stood to gain by putting up
my challenge if my own code worked adequately already.
Indeed, I was also trying to make the community (not just RT) aware of
practical and potential extensions (see
http://rebol.com/contribution_source.html ) or alternatively, refinements
to the base time!date! types involved. (see refinements below)
Being the stickler for orthogonality I am, I noted that REBOL can accept
12hour format but is not so good at emitting it (or allowing the programmer
By pointing out so many different ways one can make mistakes at the
boundaries in emitting it and getting you to come up with a concise
function that does it all, I make it attractive to be standardized or codified.
If any of you want to resubmit a better and more concise solution (read
succinct) that RT can consider for a to-ampm (like to-idate) with
refinements that allow selective inclusion/exclusion of the parts then lets
In the meantime, what if it were just a simple part of the datatypes involved?
As I have watched Rebol evolve,
being able to get [at] only what you are interested in
is a characteristic of the base type support in the language.
/year -- Returns the year only.
/month -- Returns the month only.
/day -- Returns the day of the month only.
/time -- Returns the time only.
/zone -- Returns the time zone offset from GMT only.
/date -- Returns date only.
/weekday -- Returns day of the week as integer (Sunday is day 7).
/inampm -- time portion as [h]h:mm:ss[A|P]M,
variable width hh, first hour is 12 not 0
can be combined with /time to return time only portion
/hour -- (stet)
/minute -- (stet)
/second -- (stet)
/ampm -- ante meridiem, returns "AM" or "PM"
/in12hr -- [h]h:mm:ss, variable width hh, first hour is 12 not 0
ftim: modified? %/databse/srcobjs