I am not sure what interface to use for the advanced features of the
ISO8601 parser I wrote.  Right now I use a quick hack to make it work
so I can test the parser.  It should be easy for me to change the
interface to something sane, I just don't know what that should be.

The basic usage should be:
--
my $iso = DateTime::Format::ISO8601
my $dt = $iso->parse_datetime("20030211");
--

However, I want to be able to accept the following optional arguments:
 - The classes of formats to parse (Dates, Times, DateTimes,
   Durations, Recurrences)
 - The base DateTime object to use when things are implied (e.g. the
   date component when dealing with times, or any Truncated format,
   and some recurrences)  If not supplied this defaults to now().
 - The types to allow (each group is independent so you can have a
   Basic, Reduded, Week, Fractional, Expanded DateTime format):

   - Basic (no separators)
   - Extended (with separators)

   - Complete (fully specified class, no pieces missing)
   - Reduced precision (missing lower order items, e.g. year only)

   - Truncated (whether higher order items are implied, e.g. ---12
     specifies 12th day of current month and year)

   - Fractional (Time components may be represented as a fraction)

   - Expanded (The year may have additional digits and may be negative)

   - Ordinal (Days are expressed as Nth day of a year)
   - Week (Days are expressed as Nth day of Mth ISO week)

   - Timezone (Whether a timezone is allowed)


I would also like to be able to return additional information about
the format and the parsed components.  This would allow some
introspection when dealing with an unknown format.  For instance if I
know I may get a reduced format I may want to handle it differently in
my application, but I need to know if I am dealing with a year, decade
or century.

I could handle this by detecting how many items are passed as
arguments to parse_datetime() and handling it as a hash if I get more
than 1.  Similarly I can return different items if I am called in
array context...  However, if you call parse_datetime() and get a
DateTime::Duration object back that seems wrong.

I think the thing to do is make the parse_datetime() be a wrapper for
a sub with named parameters that restricts things to DateTime objects
only.  If you want the full power of the parser you need to call
parse_iso8601() or something.  Only parse_is08601 will support
returning multiple items using wantarray to detect the calling
context.

Or I perhaps you have to make an object and call parse_datetime()
through the object if you want to do anything complex.

I am leaving the formatting side out of the intial discussion, but it
has similar problems, for instance it needs to be able to take similar
format parameters to work out what kind of string to produce.

Does anyone have any suggestions.  I looked at the existing DT::F::
modules but they don't appear to have any similar interface problems.

        Any suggestions would be appreciated.
        Thanks,

                -ben

Reply via email to