[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [MacPerl-AnyPerl] Dates, times, and month names



> At 1:07 AM -0500 3/29/1999, Ronald J. Kimball wrote:
> >Your example string is not consistent with that format...
> >
> > 4:21:00:000PM
> >hh:mm:sssPM
> >
> >I'll assume it's a typo in the example string.

Excerpt of reply (sent 28 March 1999) by Eric Albert:
> Laziness again [...]  I'd expect \d\d? for hours....

The mismatch is not in the hours, but in the seconds!

  00:000     does not really match
  sss

(that's not a regexp; it's for you humans to understand).

You continue,
> inability to handle milliseconds starting with ':' instead of '.'

aha, then you should identify the digits in
   4:21:00:000PM     with
  hh:mm:ss:ttt*M     ,
where t are milliseconds (thousandths), and * is [AP].
  
> That's easily fixed by changing (?:\.\d+)? to (?:[\.:]\d+)?

The unnecessary backslash in [.:] might confuse me.  The Camel (p. 64,
third item of rule 6) explains character classes and the special
meaning of '^', '-', '\', and ']'.  It then says:
:   Note that most other metacharacters lose their meta-ness inside
:   square brackets.

It doesn't detail the meaning of "most"; does anyone know? I verified
that period is not special.
(By the way, there is no rule 0.  Maybe Camel has its $[ == 1  :-)

Ronald J. Kimball wrote:
>Well, the months have to be hardcoded somewhere, if not in your code then
>in the module you use to do it.

Ok, what about using POSIX?  You can build up the translating hash as
follows:

    use POSIX "strftime";
    
    for (@date = (0) x 7; $date[4] < 12; $date[4]++) {
      $month_long{strftime "%b", @date} = strftime "%B", @date;
    }

or, if that's too C-ish for your taste, use nested maps:

    @dt = (0) x 7;
    %month_long = map {$dt[4] = $_; map {strftime $_, @dt} qw(%b %B)} (0..11);

To convince yourself that this works,

    print join(", ", %month_long), "\n";

Of course you migt also construct a hash from (short) monthname to
month number.  Or use Text::Abbrev

Good luck

	Christian BrechbŸhler
	
	Communication Technology Laboratory, Image Science Group
	Swiss Federal Institute of Technology (ETH), Zurich

==== Want to unsubscribe from this list?
==== Send mail with body "unsubscribe" to macperl-anyperl-request@macperl.org