Skip to content

Commit

Permalink
1.0900 2009-02-22
Browse files Browse the repository at this point in the history
	- Another pile-o-bugs
		- It seems that I also wasn't seeing notifications from RT
		  (please don't use it, use the Gooogle project) so all the
		  following are fixed:
			36672	Started failing mid May
			23313	Bug handling time zones like America/New_York
			25555	Module dies even when on_error is 'undef'
			23768	Olson timezone handling incorrect
			22450	locale test failing with bleadperl
			20487	nmake test_more fail (with patch); incorrect
					META.yml
			12071	format_datetime uses datetime locale rather than
					format locale
			11863	bug in DateTime::Format::Strptime 1.0601 when using %s
  • Loading branch information
RickMeasham committed Feb 22, 2009
1 parent 70f5e27 commit 26e8084
Show file tree
Hide file tree
Showing 8 changed files with 107 additions and 28 deletions.
18 changes: 18 additions & 0 deletions Changes
Original file line number Diff line number Diff line change
Expand Up @@ -194,3 +194,21 @@ Note on version conventions:
- It seems that I wasn't getting notifications from Google
when people had reported bugs, so there's a pile of fixes
in this release. Hopefully that fixes everyone's issues.

1.0900 2009-02-22
- Another pile-o-bugs
- It seems that I also wasn't seeing notifications from RT
(please don't use it, use the Gooogle project) so all the
following are fixed:
36672 Started failing mid May
23313 Bug handling time zones like America/New_York
25555 Module dies even when on_error is 'undef'
23768 Olson timezone handling incorrect
22450 locale test failing with bleadperl
20487 nmake test_more fail (with patch); incorrect
META.yml
12071 format_datetime uses datetime locale rather than
format locale
11863 bug in DateTime::Format::Strptime 1.0601 when using %s


1 change: 1 addition & 0 deletions MANIFEST
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ t/004_locale_defaults.t
t/005_croak.t
t/006_locales.t
t/007_edge.t
t/008_epoch.t
t/more/001_all_locales.t
2 changes: 1 addition & 1 deletion META.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ meta-spec:
version: 1.3
url: http://module-build.sourceforge.net/META-spec-v1.3.html
name: DateTime-Format-Strptime
version: 1.0800
version: 1.0900
abstract: Parse and format strp and strf time patterns
author:
- Rick Measham <rickm@cpan.org>
Expand Down
11 changes: 9 additions & 2 deletions Makefile.PL
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,16 @@ WriteMakefile(
);

sub MY::postamble {
return <<'MAKE_FRAG';
return $^O eq 'MSWin32'?
<<'MAKE_FRAG'
test_more :: pure_all
SET PERL_DL_NONLAZY=1
$(FULLPERLRUN) "-MExtUtils::Command::MM" "-e"
"test_harness($(TEST_VERBOSE), '$(INST_LIB)', '$(INST_ARCHLIB)')" t/more/*.t
MAKE_FRAG
:
<<'MAKE_FRAG';
test_more :: pure_all
PERL_DL_NONLAZY=1 $(FULLPERLRUN) "-MExtUtils::Command::MM" "-e" "test_harness($(TEST_VERBOSE), '$(INST_LIB)', '$(INST_ARCHLIB)')" t/more/*.t
MAKE_FRAG

}
24 changes: 15 additions & 9 deletions lib/DateTime/Format/Strptime.pm
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package DateTime::Format::Strptime;

use strict;

use DateTime;
use DateTime::Locale;
use DateTime::TimeZone;
Expand All @@ -11,7 +12,7 @@ use Exporter;
use vars qw( $VERSION @ISA @EXPORT @EXPORT_OK %ZONEMAP %FORMATS $CROAK $errmsg);

@ISA = 'Exporter';
$VERSION = '1.0800';
$VERSION = '1.0900';
@EXPORT_OK = qw( &strftime &strptime );
@EXPORT = ();

Expand Down Expand Up @@ -329,9 +330,14 @@ iso_week_year_100 = $iso_week_year_100
}

if ($tz_olson) {
$tz_olson = ucfirst lc $tz_olson;
$tz_olson =~ s|([/_])(\w)|$1\U$2|;
my $tz = DateTime::TimeZone->new( name => $tz_olson );
my $tz = eval { DateTime::TimeZone->new( name => $tz_olson ) };
if( not $tz ){
print "Provided olson TZ didn't work ($tz_olson). Attempting to normalize it.\n" if $self->{diagnostic};
$tz_olson = ucfirst lc $tz_olson;
$tz_olson =~ s|([/_])(\w)|$1\U$2|g;
print " Trying $tz_olson.\n" if $self->{diagnostic};
$tz = eval { DateTime::TimeZone->new( name => $tz_olson ) };
}
$self->local_croak("I don't recognise the time zone '$tz_olson'.") and return undef unless $tz;
$use_timezone = $set_time_zone = $tz;

Expand Down Expand Up @@ -439,7 +445,7 @@ iso_week_year_100 = $iso_week_year_100
# Day of the month
$self->local_croak("$day is too large to be a day of the month.") and return undef unless $day <= 31;
$self->local_croak("Your day of the month ($day) does not match your day of the year.") and return undef if $doy_dt and $day and $day != $doy_dt->day;
$Day = ($day)
$Day ||= ($day)
? $day
: ($doy_dt)
? $doy_dt->day
Expand Down Expand Up @@ -485,21 +491,21 @@ iso_week_year_100 = $iso_week_year_100

# Minutes
$self->local_croak("$minute is too large to be a minute.") and return undef unless $minute <= 59;
$Minute = $minute;
$Minute ||= $minute;
$self->local_croak("Your minute does not match your epoch.") and return undef if $epoch_dt and $Minute and $Minute != $epoch_dt->minute;
print "Set minute to $Minute.\n" if $self->{diagnostic};


# Seconds
$self->local_croak("$second is too large to be a second.") and return undef unless $second <= 59; #OK so leap seconds will break!
$Second = $second;
$Second ||= $second;
$self->local_croak("Your second does not match your epoch.") and return undef if $epoch_dt and $Second and $Second != $epoch_dt->second;
print "Set second to $Second.\n" if $self->{diagnostic};


# Nanoeconds
$self->local_croak("$nanosecond is too large to be a nanosecond.") and return undef unless length($nanosecond) <= 9;
$Nanosecond = $nanosecond;
$Nanosecond ||= $nanosecond;
$Nanosecond .= '0' while length($Nanosecond) < 9;
# Epoch doesn't return nanoseconds
# croak "Your nanosecond does not match your epoch." if $epoch_dt and $Nanosecond and $Nanosecond != $epoch_dt->nanosecond;
Expand Down Expand Up @@ -580,7 +586,7 @@ sub format_datetime {
my ( $self, $dt ) = @_;
my $pattern = $self->pattern;
$pattern =~ s/%O/$dt->time_zone->name/eg;
return $dt->strftime($pattern);
return $dt->clone->set_locale($self->locale)->strftime($pattern);
}

sub format_duration {
Expand Down
17 changes: 9 additions & 8 deletions t/002_dates.t
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ use DateTime::TimeZone;
my $object = DateTime::Format::Strptime->new(
pattern => '%D',
# time_zone => 'Australia/Melbourne',
diagnostic => 0,
diagnostic => 1,
on_error => 'croak',
);

my @tests = (
Expand All @@ -24,7 +25,7 @@ my @tests = (
# Simple times
['%H:%M:%S', '23:45:56'],
['%l:%M:%S %p', '11:34:56 PM'],

# With Nanoseconds
['%H:%M:%S.%N', '23:45:56.123456789'],
['%H:%M:%S.%6N', '23:45:56.123456'],
Expand All @@ -43,30 +44,30 @@ foreach (@tests) {
}

SKIP: {
skip "You don't have the latest DateTime. Older version have a bug whereby 12am and 12pm are shown as 0am and 0pm. You should upgrade.", 1
skip "You don't have the latest DateTime. Older version have a bug whereby 12am and 12pm are shown as 0am and 0pm. You should upgrade.", 1
unless $DateTime::VERSION >= 0.11;

$object->pattern('%l:%M:%S %p');
is($object->format_datetime( $object->parse_datetime( '12:34:56 AM' ) ),
is($object->format_datetime( $object->parse_datetime( '12:34:56 AM' ) ),
'12:34:56 AM', '%l:%M:%S %p');
}


# Timezones
SKIP: {
skip "You don't have the latest DateTime::TimeZone. Older versions don't display all time zone information. You should upgrade.", 3
skip "You don't have the latest DateTime::TimeZone. Older versions don't display all time zone information. You should upgrade.", 3
unless $DateTime::TimeZone::VERSION >= 0.13;

$object->pattern('%H:%M:%S %z');
is($object->format_datetime( $object->parse_datetime( '23:45:56 +1000' ) ),
is($object->format_datetime( $object->parse_datetime( '23:45:56 +1000' ) ),
'23:45:56 +1000', '%H:%M:%S %z');

$object->pattern('%H:%M:%S %Z');
is($object->format_datetime( $object->parse_datetime( '23:45:56 AEST' ) ),
is($object->format_datetime( $object->parse_datetime( '23:45:56 AEST' ) ),
'23:45:56 +1000', '%H:%M:%S %Z');

$object->pattern('%H:%M:%S %z %Z');
is($object->format_datetime( $object->parse_datetime( '23:45:56 +1000 AEST' ) ),
is($object->format_datetime( $object->parse_datetime( '23:45:56 +1000 AEST' ) ),
'23:45:56 +1000 +1000', '%H:%M:%S %z %Z');
}

Expand Down
42 changes: 35 additions & 7 deletions t/006_locales.t
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# t/002_basic.t - check module dates in various formats

use Test::More tests => 252;
use Test::More tests => 257;
#use Test::More qw/no_plan/;
use DateTime::Format::Strptime;
use DateTime;
Expand All @@ -21,14 +21,14 @@ foreach my $locale ( @locales ) {
on_error=> 'croak',
)};
ok($@ eq '',"Constructor with Day Name");

my $parsed;
eval {
$parsed = $strptime->parse_datetime($input);
} unless $@;
diag("[$@]") if $@ ne '';
ok($@ eq '',"Parsed with Day Name");

is($parsed->strftime($pattern),$input,"Matched with Day Name");
}
# diag( $locale );
Expand All @@ -46,14 +46,14 @@ foreach my $locale ( @locales ) {
on_error=> 'croak',
)};
ok($@ eq '',"Constructor with Month Name");

my $parsed;
eval {
$parsed = $strptime->parse_datetime($input);
} unless $@;
diag("[$@]") if $@ ne '';
ok($@ eq '',"Parsed with Month Name");

is($parsed->strftime($pattern),$input,"Matched with Month Name");
}
# diag( $locale );
Expand All @@ -71,16 +71,44 @@ foreach my $locale ( @locales ) {
on_error=> 'croak',
)};
ok($@ eq '',"Constructor with Meridian");

my $parsed;
eval {
$parsed = $strptime->parse_datetime($input);
} unless $@;
diag("[$@]") if $@ ne '';
ok($@ eq '',"Parsed with Meridian");

is($parsed->strftime($pattern),$input,"Matched with Meridian");
}
# diag( $locale );
}

#diag("\nChecking format_datetime honors strptime's locale rather than the dt's");
{
# Create a parser that has locale 'fr'
my $dmy_format = new DateTime::Format::Strptime(
pattern => '%d/%m/%Y',
locale => 'fr'
);
is( $dmy_format->locale, 'fr');

# So, therefore, will a $dt created using it.
my $dt = $dmy_format->parse_datetime('03/08/2004');
is( $dt->locale->id, 'fr');

# Now we create a new strptime for formatting, but in a different locale
my $pt_format = new DateTime::Format::Strptime(
pattern => '%B/%Y',
locale => 'pt'
);
is( $pt_format->locale, 'pt');

my $string = $pt_format->format_datetime($dt);

# Make sure the format honored the locale in the strptime
is( $string, "agosto/2004" );

# Make sure the datetime, however, retained its own locale
is( $dt->locale->id, 'fr' )
}
20 changes: 19 additions & 1 deletion t/007_edge.t
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# t/007_edge.t - these tests are for edge case bug report errors

use Test::More tests => 12;
use Test::More tests => 15;
use DateTime;
use DateTime::Format::Strptime;

Expand Down Expand Up @@ -57,6 +57,24 @@ isnt($@ , '', "Illegal input should carp");
is(substr($@,0,39), 'Datetime 0000-00-00 is not a valid date', "Croak message should reflect illegal pattern");


#diag("1.09 - Time zones with an underscore");
{
my $parser = new DateTime::Format::Strptime( pattern => '%O' );
is($parser->parse_datetime('America/New_York')->time_zone->name, 'America/New_York');
}

#diag("1.09 - TZs in the wrong case should work (unless they have a cap in the middle of a word)");
{
my $parser = new DateTime::Format::Strptime( pattern => '%O', diagnostic => 1 );
is($parser->parse_datetime('AMERICA/NEW_YORK')->time_zone->name, 'America/New_York');
}

#diag("1.09 - Bogus TZs shouldn't barf, they should follow the on_error setting");
{
my $parser = new DateTime::Format::Strptime( pattern => '%O', on_error => 'undef' );
is($parser->parse_datetime('Oz/Munchkinville'), undef);
}


sub test {
my %arg = @_;
Expand Down

0 comments on commit 26e8084

Please sign in to comment.