Hi Rick,

Here is a simple patch that:

uses DT::Locale instead of DT::Language
maintains full backwards compatibility (well at least all the existing tests pass)
adds support for a 'locale' in the constructor
adds a locale method (alias for the language method)
adds tests for a pattern specified with a locale
adds a missing file to the MANIFEST
updates the docs for changes
fixes the dependencies in Makefile.PL

There were no existing tests for the language method so I can't be certain it didn't 
break (although I don't think it did).  Also the tests I added for using a locale in 
the constructor are inadequate.

It does not:

update the Changes file
update the VERSION

Cheers,

-J

--
diff -ru old.DateTime-Format-Strptime-1.03/MANIFEST DateTime-Format-Strptime/MANIFEST
--- old.DateTime-Format-Strptime-1.03/MANIFEST  2003-05-28 01:08:27.000000000 -1000
+++ DateTime-Format-Strptime/MANIFEST   2003-07-28 22:39:14.000000000 -1000
@@ -7,5 +7,5 @@
 t/001_load.t
 t/002_dates.t
 t/003_every.t
+t/004_croak.t
 Makefile.PL
-
diff -ru old.DateTime-Format-Strptime-1.03/Makefile.PL 
DateTime-Format-Strptime/Makefile.PL
--- old.DateTime-Format-Strptime-1.03/Makefile.PL       2003-06-06 14:53:40.000000000 
-1000
+++ DateTime-Format-Strptime/Makefile.PL        2003-07-28 21:59:02.000000000 -1000
@@ -6,11 +6,9 @@
     AUTHOR       => 'Rick Measham ([EMAIL PROTECTED])',
     ABSTRACT     => 'Parse and format strp and strf time patterns',
     PREREQ_PM    => {
-       'DateTime'           => 0.13,
-       'DateTime::Language' => 0,
-       'DateTime::TimeZone' => 0.18,
-       'Params::Validate'   => 0,
-       'Carp'               => 0,
-       'Exporter'           => 0,
+       'DateTime'           => '0.1402',
+       'DateTime::Locale'   => '0.02',
+       'DateTime::TimeZone' => '0.25',
+       'Params::Validate'   => '0.64',
     },
 );
diff -ru old.DateTime-Format-Strptime-1.03/lib/DateTime/Format/Strptime.pm 
DateTime-Format-Strptime/lib/DateTime/Format/Strptime.pm
--- old.DateTime-Format-Strptime-1.03/lib/DateTime/Format/Strptime.pm   2003-06-25 
02:51:25.000000000 -1000
+++ DateTime-Format-Strptime/lib/DateTime/Format/Strptime.pm    2003-07-28 
22:34:30.000000000 -1000
@@ -126,11 +126,16 @@
        my %args = validate( @_, {      pattern         => { type => SCALAR },
                                                                time_zone       => { 
type => SCALAR | OBJECT, optional => 1 },
                                                                language        => { 
type => SCALAR | OBJECT, default => 'English' },
+                                                               locale          => { 
type => SCALAR | OBJECT, optional => 1 },
                                                                on_error        => { 
type => SCALAR | CODEREF, default => 'undef' },
                                                                diagnostic      => { 
type => SCALAR, default => 0 },
                              }
                        );
-
+
+       if ( exists $args{ locale } ) {
+               $args{ language } = delete $args{ locale };
+       }
+
        croak("The value supplied to on_error must be either 'croak', 'undef' or a 
code reference.")
                unless ref($args{on_error}) eq 'CODE'
                        or $args{on_error} eq 'croak'
@@ -139,7 +144,7 @@

        # Deal with language
        unless (ref ($args{language})) {
-               my $language = DateTime::Language->new(language => $args{language});
+               my $language = DateTime::Locale->load( $args{language} );

                croak("Could not create language from $args{language}") unless 
$language;

@@ -192,7 +197,7 @@
        my $language = shift;

        if ($language) {
-               my $possible_language = DateTime::Language->new(language => $language);
+               my $possible_language = DateTime::Locale->load( $language );
                unless ($possible_language) {
                        $self->local_carp("Could not create language from $language. 
Leaving old language intact.") and return undef;
                } else {
@@ -203,6 +208,8 @@
        return $self->{language};
 }

+*locale = \&language;
+
 sub time_zone {
        my $self = shift;
        my $time_zone = shift;
@@ -244,7 +251,7 @@

        # Locale-ize the parser
        my $locale_parser = $self->{parser};
-               my $ampm_list = join('|', @{$self->{_language}->am_pm_list});
+               my $ampm_list = join('|', @{$self->{_language}->am_pms});
                $ampm_list .= '|' . lc $ampm_list;
                $locale_parser=~s/LOCALE:AMPM/$ampm_list/g;

@@ -798,7 +805,7 @@
 =item * new( pattern=>$strptime_pattern )

 Creates the format object. You must specify a pattern, you can also
-specify a C<time_zone> and C<language>. If you specify a time zone,
+specify a C<time_zone> and either a C<language> or a C<locale>. If you specify a time 
zone,
 then any resulting C<DateTime> object will be in that time zone. If you
 do not specify a C<time_zone> parameter, but there is a time zone in the
 string you pass to C<parse_datetime>, then the resulting C<DateTime> will
@@ -869,6 +876,15 @@
 If successful this method returns the current language. (After
 processing as above)

+=item * locale($locale)
+
+When given a locale, this method sets its locale appropriately. If
+the locale is not understood, the method will croak or return undef
+(depending on the value of $DateTime::Format::Strptime::CROAK)
+
+If successful this method returns the current locale. (After
+processing as above)
+
 =item * pattern($strptime_pattern)

 When given a pattern, this method sets the object's pattern. If the
@@ -994,8 +1010,8 @@

 =item * %p

-The equivalent of AM or PM according to the language in use. (See
-L<DateTime::Language>)
+The equivalent of AM or PM according to the locale in use. (See
+L<DateTime::Locale>)

 =item * %r

diff -ru old.DateTime-Format-Strptime-1.03/t/003_every.t 
DateTime-Format-Strptime/t/003_every.t
--- old.DateTime-Format-Strptime-1.03/t/003_every.t     2003-06-06 13:33:22.000000000 
-1000
+++ DateTime-Format-Strptime/t/003_every.t      2003-07-28 22:36:40.000000000 -1000
@@ -1,44 +1,88 @@
 # t/002_basic.t - check module dates in various formats

-use Test::More tests => 7;
+use Test::More tests => 14;
 use DateTime::Format::Strptime;

-my $object = DateTime::Format::Strptime->new(
-       pattern => '%D',
-       time_zone => 'Australia/Melbourne',
-       language => 'English',
-       diagnostic => 0,
-);
-
-my $epoch = DateTime->new(
-       year => 2003, month => 11, day => 5,
-       hour => 23, minute => 34, second => 45,
-       time_zone => 'Australia/Melbourne'
-)->epoch;
-
-
-my @tests = (
-       # Compound Patterns
-       ['%T',  '23:34:45', '24-hour Time'],
-       ['%r', '11:34:45 PM', '12-hour Time'],
-       ['%R', '23:34', 'Simple 24-hour Time'],
-       ['%D', '11/30/03', 'American Style Date'],
-       ['%F', '2003-11-30', 'ISO Style Date'],
-
-       ['%a %b %B %C %d %e %h %H %I %j %k %l %m %M %n %N %p %P %S %U %u %w %W %y %Y 
%s %G %g %z %Z %%',
-       "Wed Nov November 20 05  5 Nov 23 11 309 23 11 11 34 \n 123456789 PM pm 45 44 
3 3 44 03 2003 $epoch 2003 03 +1100 EST %",
-       "Every token at once"],
+{
+       my $object = DateTime::Format::Strptime->new(
+               pattern => '%D',
+               time_zone => 'Australia/Melbourne',
+               language => 'English',
+               diagnostic => 0,
+       );

-       ['%{year}', '2003', 'Extended strftime %{} matching'],
-
-);
+       my $epoch = DateTime->new(
+               year => 2003, month => 11, day => 5,
+               hour => 23, minute => 34, second => 45,
+               time_zone => 'Australia/Melbourne'
+       )->epoch;
+
+
+       my @tests = (
+               # Compound Patterns
+               ['%T',  '23:34:45', '24-hour Time'],
+               ['%r', '11:34:45 PM', '12-hour Time'],
+               ['%R', '23:34', 'Simple 24-hour Time'],
+               ['%D', '11/30/03', 'American Style Date'],
+               ['%F', '2003-11-30', 'ISO Style Date'],
+
+               ['%a %b %B %C %d %e %h %H %I %j %k %l %m %M %n %N %p %P %S %U %u %w %W 
%y %Y %s %G %g %z %Z %%',
+               "Wed Nov November 20 05  5 Nov 23 11 309 23 11 11 34 \n 123456789 PM 
pm 45 44 3 3 44 03 2003 $epoch 2003 03 +1100 EST %",
+               "Every token at once"],
+
+               ['%{year}', '2003', 'Extended strftime %{} matching'],
+
+       );
+
+       foreach (@tests) {
+               my ($pattern, $data, $name) = @$_;
+               $name ||= $pattern;
+               #print "-- $pattern ($data) --\n";
+               $object->pattern($pattern);
+               #print $object->parse_datetime( $data )->strftime("%Y-%m-%d 
%H:%M:%S\n");
+               #print $object->parse_datetime( $data )->strftime("Got: $pattern\n");
+               is($object->format_datetime( $object->parse_datetime( $data ) ), 
$data, $name);
+       }
+}

-foreach (@tests) {
-       my ($pattern, $data, $name) = @$_;
-       $name ||= $pattern;
-       #print "-- $pattern ($data) --\n";
-       $object->pattern($pattern);
-       #print $object->parse_datetime( $data )->strftime("%Y-%m-%d %H:%M:%S\n");
-       #print $object->parse_datetime( $data )->strftime("Got: $pattern\n");
-       is($object->format_datetime( $object->parse_datetime( $data ) ), $data, $name);
+{
+       my $object = DateTime::Format::Strptime->new(
+               pattern => '%D',
+               time_zone => 'Australia/Melbourne',
+               locale => 'en_AU',
+               diagnostic => 0,
+       );
+
+       my $epoch = DateTime->new(
+               year => 2003, month => 11, day => 5,
+               hour => 23, minute => 34, second => 45,
+               time_zone => 'Australia/Melbourne'
+       )->epoch;
+
+
+       my @tests = (
+               # Compound Patterns
+               ['%T',  '23:34:45', '24-hour Time'],
+               ['%r', '11:34:45 PM', '12-hour Time'],
+               ['%R', '23:34', 'Simple 24-hour Time'],
+               ['%D', '11/30/03', 'American Style Date'],
+               ['%F', '2003-11-30', 'ISO Style Date'],
+
+               ['%a %b %B %C %d %e %h %H %I %j %k %l %m %M %n %N %p %P %S %U %u %w %W 
%y %Y %s %G %g %z %Z %%',
+               "Wed Nov November 20 05  5 Nov 23 11 309 23 11 11 34 \n 123456789 PM 
pm 45 44 3 3 44 03 2003 $epoch 2003 03 +1100 EST %",
+               "Every token at once"],
+
+               ['%{year}', '2003', 'Extended strftime %{} matching'],
+
+       );
+
+       foreach (@tests) {
+               my ($pattern, $data, $name) = @$_;
+               $name ||= $pattern;
+               #print "-- $pattern ($data) --\n";
+               $object->pattern($pattern);
+               #print $object->parse_datetime( $data )->strftime("%Y-%m-%d 
%H:%M:%S\n");
+               #print $object->parse_datetime( $data )->strftime("Got: $pattern\n");
+               is($object->format_datetime( $object->parse_datetime( $data ) ), 
$data, $name);
+       }
 }

Reply via email to