On Tue, Jul 15, 2003 at 12:14:00AM -0400, John Siracusa wrote:
> On 7/14/03 11:10 PM, Ben Bennett wrote:
[...]
> Sweet, someone took the bai--...er, "picked up the baton" ;)

Well I have been playing around with the idea for a while, but when
the locale stuff got in I decided it was time to stop fiddling and get
something useful together.
 
> I'm sure you're already doing this, but just in case, make sure to allow for
> single-digit numbers where there is no ambiguity.  This is essential for
> handling "user-created" input.  Examples:
> 
>     9/3/2002 (e.g. don't require 09/03/2002)
>     1:02     (e.g. don't require 01:02)

Yes.

> and maybe even:
> 
>     200210131:02

No!  Egads :-)  Actually I wasn't accepting the form 200210130102
either (I will accept 20021013T0102).  Should I?

> but that may make some people break out in hives, so whatever :)

Scratch, scratch...

> Also,
> don't forget about the optional "." in "a.m." and "p.m."  I'm not quite sure
> how that'd get localized, but the point is that the localized am/pm thingies
> must be regexes, not constant strings (or, okay, a regex constructed out of
> a list of constant strings, if you want :)

Yeah, I was trying to work that out.  It appears not to be in the raw
locale data, so I was considering just accepting the am/pm stuff with
optional inserted periods, even for other locales.  I still have to
survey all locales to see if that is even reasonable.  The other
choice would be to special case BC and AD to allow the dotted form,
but that seems a bit restrictive.
 
> > Which leads to my problem, there appears to be no simple way to get
> > the date order to differentiate m/d/y from d/m/y.
> 
> Don't.  Make it a setting.  I've been trying to think of what to name this
> setting, but have no good ideas.  Here are some bad ones instead:

It would be a setting... locale.

>     DT::F::Simple->use_mmddyyyy(1);
>     DT::F::Simple->use_ddmmyyyy(1);
> 
>     DT::F::Simple->mode('us');
>     DT::F::Simple->mode('euro');
> 
>     DT::F::Simple->euro_mode(1);
>     DT::F::Simple->us_mode(1);
> 
> Gah, that's horrible :)  Someone out there must have some sort of
> pre-existing vocabulary to describe the date format differences.  Is it just
> regional, or are there ISO numbers to reference or what?

I can add an optional additional parameter dmy_mode (defaults to your
locale if undef) but I really think inferring it from the locale is
fine.

Speaking of which, what interface do people want?

  my $us_parser = DateTime::Format::Simple->new(locale => "en_US");
  my $dt = $us_parser->parse_datetime("2/11/74");

Or:

  my $dt = DateTime::Format::Simple->parse_datetime(string => "2/11/74",
                                                    locale => "en_US");

Note that it will always be legal to call:
  my $dt = DateTime::Format::Simple->parse_datetime("2/11/74");

And some locale will be assumed (probably en_US).

Another choice would be to allow both forms (which I may do to allow
user flexilbility).

                        -ben

Reply via email to