On Tue, Jan 14, 2003 at 10:49:29PM -0600, Dave Rolsky wrote:
> The other syntax you propose isn't that bad, but how does it scale when
> you want to have multiple parsers and formatters A) as defaults; and B)
> per object?

I was thinking that there would be parsedate() and formatdate()
methods that would use the per-object parser/formatter if specified,
otherwise use the defaults.   The parser/formatter could be specified
"globally", per-object, or per-call.

As for multiple parsers, here are some ideas:

        use DateTime ( 
           Defaults=> { parser => [ Parser1, Parser2, Parser3 ], ...  }
        );

Calls to parsedate() could try the parsers in order until one succeeds
(returns something other than undef). Or they could all be tried and the
DateTime object will contain an array of possible parsings that is
somehow accessible. Or they could be tried superpositionally with some
mechanism to collapse to a give parsing.  

Multiple parsers only make sense when you don't really know what
format the date is it.  I like the call-them-in-order method because
the others make me worry about what happens when more than one parser
successfully parses the date.  (What if they get different results?)

I can't see how multiple default formatters would make sense.  You generally
only want to format a date/time one way at a time.  But maybe, as I
suggest for the parsers, there could be a mechanism to format the
date/time in multiple ways at once then choose the representation that
makes sense.  Hmm.

        $dto->formatdate({ formatter => [ F1, F2, F3 ]});
        $f1str = $dto->F1;
        $f2str = $dto->F2;

I don't like it.

> And how do you actually do parsing/formatting once the classes/objects are
> known by the DateTime object at hand?

Through the parsedate() and formatdate() routines.

        # use the DateTime default
        $dt0 = DateTime::parsedate($string);

        # use the CustomDate parser
        $dt1 = DateTime::parsedate($string, { parser => CustomDate } );

        # use either the DateTime default or whatever was specified when
        # the object was created
        $dt2->parsedate($string);

        # reparse the $string into $dt2, but use a different parser
        $dt2->parsedate($string, { parser => CustomDate } );

        # use the DateTime default formatter
        $str0 = DateTime::formatdate($format);

        # use the $dto object's formatter
        $str1 = $dto->formatdate($format);

        # format the $dto object using the CustomFormat
        $str2 = $dto->formatdate($format, { formatter => CustomFormat } );


-Scott
-- 
Jonathan Scott Duff
[EMAIL PROTECTED]

Reply via email to