Hello everybody,

I've just released 0.24 of DateTime::Format::Builder.

You'll find it at your local CPAN eventually, in the CVS now, and
also at http://perl.dellah.org/modules/ right now.

It's still lacking tests. Docs need some work but I won't get a chance
until Thursday night to look at that properly.[1] I'm GMT+11 at present,
so don't feel shy about sending patches to the code or documentation.

I'm not expecting the API to change much, unless someone says it sucks.
[Joshua: it hasn't changed significantly from the 0.23 you got earlier
today.]

Bugs/comments/whatever to here or [EMAIL PROTECTED]  - the rt.cpan.org
address won't be available for a small while.


For your amusement, a ICal.pm patch is attached.


cheers,
-- 
Iain.

[1] The reason being that I'm having too much fun with
    DateTime::Parse::Strptime
? Makefile
? blib
? diffs
? pm_to_blib
Index: Makefile.PL
===================================================================
RCS file: /cvsroot/perl-date-time/modules/DateTime-Format-ICal/Makefile.PL,v
retrieving revision 1.2
diff -u -r1.2 Makefile.PL
--- Makefile.PL 8 Feb 2003 21:36:53 -0000       1.2
+++ Makefile.PL 25 Mar 2003 02:00:59 -0000
@@ -4,5 +4,8 @@
                VERSION_FROM => 'lib/DateTime/Format/ICal.pm',
                AUTHOR       => 'Dave Rolsky <[EMAIL PROTECTED]>',
                ABSTRACT     => 'Formatting and Parsing of iCal formats',
-               PREREQ_PM    => { 'DateTime' => 0 },
+               PREREQ_PM    => {
+                  'DateTime' => 0,
+                  'DateTime::Format::Builder' => '0.24',
+              },
              );
Index: lib/DateTime/Format/ICal.pm
===================================================================
RCS file: 
/cvsroot/perl-date-time/modules/DateTime-Format-ICal/lib/DateTime/Format/ICal.pm,v
retrieving revision 1.6
diff -u -r1.6 ICal.pm
--- lib/DateTime/Format/ICal.pm 16 Feb 2003 17:23:01 -0000      1.6
+++ lib/DateTime/Format/ICal.pm 25 Mar 2003 02:00:59 -0000
@@ -1,6 +1,7 @@
 package DateTime::Format::ICal;
 
 use strict;
+use DateTime::Format::Builder;
 
 use vars qw ($VERSION);
 
@@ -8,66 +9,53 @@
 
 use DateTime;
 
-sub new
-{
-    my $class = shift;
-
-    return bless {}, $class;
-}
-
-# key is string length
-my %valid_formats =
-    ( 15 =>
-      { params => [ qw( year month day hour minute second ) ],
-        regex  => qr/^(\d\d\d\d)(\d\d)(\d\d)T(\d\d)(\d\d)(\d\d)$/,
-        zero   => {},
-      },
-      13 =>
-      { params => [ qw( year month day hour minute ) ],
-        regex  => qr/^(\d\d\d\d)(\d\d)(\d\d)T(\d\d)(\d\d)$/,
-        zero   => { second => 0 },
-      },
-      11 =>
-      { params => [ qw( year month day hour ) ],
-        regex  => qr/^(\d\d\d\d)(\d\d)(\d\d)T(\d\d)$/,
-        zero   => { minute => 0, second => 0 },
-      },
-      8 =>
-      { params => [ qw( year month day ) ],
-        regex  => qr/^(\d\d\d\d)(\d\d)(\d\d)$/,
-        zero   => { hour => 0, minute => 0, second => 0 },
-      },
-    );
-
-sub parse_datetime
-{
-    my ( $self, $date ) = @_;
-
-    # save for error messages
-    my $original = $date;
-
-    my %p;
+my $add_tz = sub {
+    my %args = @_;
+    my ($date, $p) = @args{qw( input parsed )};
     if ( $date =~ s/^TZID=([^:]+):// )
     {
-        $p{time_zone} = $1;
+        $p->{time_zone} = $1;
     }
     # Z at end means UTC
     elsif ( $date =~ s/Z$// )
     {
-        $p{time_zone} = 'UTC';
+        $p->{time_zone} = 'UTC';
     }
     else
     {
-        $p{time_zone} = 'floating';
+        $p->{time_zone} = 'floating';
     }
+    return $date;
+};
 
-    my $format = $valid_formats{ length $date }
-        or die "Invalid ICal datetime string ($original)";
-
-    @p{ @{ $format->{params} } } = $date =~ /$format->{regex}/;
-
-    return DateTime->new( %p, %{ $format->{zero} } );
-}
+DateTime::Format::Builder->create_class(
+    parsers => {
+       parse_datetime => [
+       [ preprocess => $add_tz ],
+# key is string length
+       {
+           length => 15,
+           params => [ qw( year month day hour minute second ) ],
+           regex  => qr/^(\d\d\d\d)(\d\d)(\d\d)T(\d\d)(\d\d)(\d\d)$/,
+       },
+       {
+           length => 13,
+           params => [ qw( year month day hour minute ) ],
+           regex  => qr/^(\d\d\d\d)(\d\d)(\d\d)T(\d\d)(\d\d)$/,
+       },
+       {
+           length => 11,
+           params => [ qw( year month day hour ) ],
+           regex  => qr/^(\d\d\d\d)(\d\d)(\d\d)T(\d\d)$/,
+       },
+       {
+           length => 8,
+           params => [ qw( year month day ) ],
+           regex  => qr/^(\d\d\d\d)(\d\d)(\d\d)$/,
+       },
+       ]
+    }
+);
 
 sub parse_duration
 {

Attachment: pgp00000.pgp
Description: PGP signature

Reply via email to