Changeset 1745

Show
Ignore:
Timestamp:
10/14/06 14:19:10
Author:
miyagawa
Message:

fix Plagger::Date->parse_dwim to handle date-only string. This fixes Publish::iCal test failure

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/plagger/lib/Plagger/Date.pm

    r1744 r1745  
    2828 
    2929    require Date::Parse; 
    30     my($sec, $min, $hour, $day, $month, $year, $zone) = Date::Parse::strptime($str)
    31     defined $sec or return
     30    my %p
     31    @p{qw( second minute hour day month year zone )} = Date::Parse::strptime($str)
    3232 
    33     my $dt = $class->new( 
    34         year   => $year + 1900, 
    35         month  => $month + 1, 
    36         day    => $day, 
    37         hour   => $hour, 
    38         minute => $min, 
    39         second => $sec, 
    40     ); 
     33    unless (defined($p{year}) && defined($p{month}) && defined($p{day})) { 
     34        return; 
     35    } 
     36 
     37    $p{year} += 1900; 
     38    $p{month}++; 
     39 
     40    my $zone = delete $p{zone}; 
     41    for (qw( second minute hour )) { 
     42        delete $p{$_} unless defined $p{$_}; 
     43    } 
     44 
     45    my $dt = $class->new(%p); 
    4146 
    4247    if (defined $zone) { 
  • trunk/plagger/t/core/date-parse.t

    r1743 r1745  
    3838--- expected 
    39392006-10-14T12:55:00Z 
     40 
     41=== date only 
     42--- input 
     432006/10/14 
     44--- expected 
     452006-10-14T00:00:00