diff --git a/Changes b/Changes index 215e795..eef98b2 100644 --- a/Changes +++ b/Changes @@ -2,6 +2,9 @@ TODO: - Add some syntactic sugar to make timezone conversion easier - Performs multiple conversion in one call (via []) +0.076 Saturday November 10 22:27:39 PST 2007: + - Fixed some failing tests due to inability to determine local timezone + 0.075 Friday November 09 13:06:05 PST 2007: - Fixed "unable to parse" bug in ::Format::DateManip and ::Format::Flexible parsing diff --git a/lib/DateTimeX/Easy.pm b/lib/DateTimeX/Easy.pm index 19f4ffc..acd43bb 100644 --- a/lib/DateTimeX/Easy.pm +++ b/lib/DateTimeX/Easy.pm @@ -9,11 +9,11 @@ DateTimeX::Easy - Parse a date/time string using the best method available =head1 VERSION -Version 0.075 +Version 0.076 =cut -our $VERSION = '0.075'; +our $VERSION = '0.076'; =head1 SYNOPSIS @@ -271,6 +271,22 @@ eval { }; my $natural_parser = DateTime::Format::Natural->new; +my %_truncate_range = qw/ + month year + day month + hour day + minute hour + second minute + nanosecond second +/; +my %_delta_range = ( + month => [qw/years months/], + day => [qw/months days/], + hour => [qw/days hours/], + minute => [qw/hours minutes/], + second => [qw/minutes seconds/], +); + my @_parser_order = qw/DateParse Natural Flexible/; unshift @_parser_order, qw/ICal/ if $have_ICal; push @_parser_order, qw/DateManip/ if $have_DateManip; @@ -343,11 +359,10 @@ sub new { } else { - { + if (0) { my $range = "year|month|day|hour|minute|second"; - $beginning_of = $1 if $parse =~ s/^\s*begin(?:ning)?\s+($range)\s+of\s+//i; - $beginning_of = $1 if ! $beginning_of && $parse =~ s/^\s*start(?:ing)?\s+($range)\s+of\s+//i; - $end_of = $1 if ! $beginning_of && $parse =~ s/^\s*end(?:ing)?\s+($range)of\s+//i; + $beginning_of = $1 if $parse =~ s/^\s*(?:start|first|begin(?:ning)?)\s+($range)\s+of\s+//i; + $end_of = $1 if ! $beginning_of && $parse =~ s/^\s*(?:last|end(?:ing)?)\s+($range)\s+of\s+//i; } my @parser_order = $parser_order ? (ref $parser_order eq "ARRAY" ? @$parser_order : ($parser_order)) : @_parser_order; @@ -392,14 +407,21 @@ sub new { $truncate = (values %$truncate)[0] if ref $truncate eq "HASH"; $dt->truncate(to => $truncate); } - elsif ($beginning_of) { - # Beta feature, doesn't work yet - $dt->truncate(to => lc $beginning_of); - } - elsif ($end_of) { - # Beta feature, doesn't work yet - # TODO Not ready yet - } +# elsif ($beginning_of) { +# my $truncate = $_truncate_range{$beginning_of}; +# $dt->truncate(to => $truncate); +# } +# elsif ($end_of) { +# my $truncate = $_truncate_range{$end_of}; +# my $delta = $_delta_range{$end_of}; +# if ($delta) { +# my ($add, $subtract) = @$delta; +# $dt->truncate(to => $truncate); +# for (qw/year month day hour minute second/) { +# } +# $dt->add($add => 1)->subtract($subtract => 1); +# } +# } return $dt; } diff --git a/t/01-DateTimeX-Easy.t b/t/01-DateTimeX-Easy.t index a730570..09370ea 100644 --- a/t/01-DateTimeX-Easy.t +++ b/t/01-DateTimeX-Easy.t @@ -6,6 +6,12 @@ use warnings; use Test::More qw/no_plan/; use DateTimeX::Easy qw/parse_datetime datetime/; +my $local_time_zone; +eval { + $local_time_zone = DateTime::TimeZone->new(name => "local"); +}; +undef $local_time_zone if $@; + my $dt; $dt = DateTimeX::Easy->new("2007/01/01"); is("$dt", "2007-01-01T00:00:00"); @@ -50,7 +56,23 @@ $dt = datetime(parse => "2007/01/01 23:22:01 PST8PDT", time_zone => "UTC"); is("$dt", "2007-01-02T07:22:01"); is($dt->time_zone->name, "UTC"); -ok(datetime("2007-10")); +ok($dt = datetime("2007-10")); +is("$dt", "2007-10-01T00:00:00"); +is($dt->time_zone->name, "floating"); + +#TODO: { +# ok($dt = datetime("beginning day of 2007-10-02")); +# is("$dt", "2007-10-01T00:00:00"); +# is($dt->time_zone->name, "floating"); + +# ok($dt = datetime("end day of 2007-10-02")); +# is("$dt", "2007-10-31T00:00:00"); +# is($dt->time_zone->name, "floating"); + +# ok($dt = datetime("last month of 2007")); +# is("$dt", "2007-12-01T00:00:00"); +# is($dt->time_zone->name, "floating"); +#}; { $dt = DateTimeX::Easy->new("today"); @@ -100,8 +122,11 @@ ok(datetime("2007-10")); ok($eg->time_zone->is_floating); is("$eg", "2007-07-01T22:32:10"); - $eg = DateTimeX::Easy->parse("2007-07-01 10:32:10", time_zone_if_floating => "local"); # Will use the local timezone - is($eg->time_zone->name, DateTime::TimeZone->new(name => "local")->name); + SKIP: { + skip "Can't determine local timezone", 1 unless $local_time_zone; + $eg = DateTimeX::Easy->parse("2007-07-01 10:32:10", time_zone_if_floating => "local"); # Will use the local timezone + is($eg->time_zone->name, $local_time_zone->name); + } $eg = DateTimeX::Easy->parse("2007-07-01 10:32:10 UTC", time_zone => "US/Pacific"); # Will convert from UTC to US/Pacific is($eg->time_zone->name, "America/Los_Angeles");