Show
Ignore:
Timestamp:
04/03/08 08:14:20 (20 months ago)
Author:
fumiakiy
Message:

Implemented MT::DateTime::compare. BugId:67917

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • branches/release-33/t/45-datetime.t

    r1098 r1744  
    2424 
    2525my $num_tests = 3; 
    26 plan tests => (scalar @dates) * $num_tests; 
     26plan tests => 9 + (scalar @dates) * $num_tests; 
    2727 
    2828foreach my $dh (@dates) { 
     
    6767} 
    6868 
     69# compare tests 
     70my $t = time(); 
     71ok( (MT::DateTime->compare( a => '20080401123456', b => '20080401123456' ) == 0), 'the same time is equal to each other'); 
     72ok( (MT::DateTime->compare( a => '20080401123457', b => '20080401123456' ) > 0), 'a > b returns positive'); 
     73ok( (MT::DateTime->compare( a => '20080401123456', b => '20080501123456' ) < 0), 'a < b returns negative'); 
     74ok( (MT::DateTime->compare( a => { value => $t, type => 'epoch' }, b => { value => $t, type => 'epoch' } ) == 0), 'the same time is equal to each other'); 
     75ok( (MT::DateTime->compare( b => { value => $t, type => 'epoch' }, a => { value => $t, type => 'epoch' } ) == 0), 'the same time is equal to each other'); 
     76ok( (MT::DateTime->compare( b => { value => time(), type => 'epoch' }, a => '20080101235959' ) < 0), 'today is larger than Jan 1st 23:59:59, 2008'); 
     77ok( (MT::DateTime->compare( a => { value => time(), type => 'epoch' }, b => '20080101235959' ) > 0), 'today is larger than Jan 1st 23:59:59, 2008'); 
     78my $dt1 = MT::DateTime->new( %{$dates[0]} ); 
     79my $dt2 = MT::DateTime->new( %{$dates[$#dates]} ); 
     80ok( ($dt1->compare(a => { value => $dt2, type => 'datetime' }) > 0), 
     81    sprintf("%04d-%02d-%02d %02d:%02d:%02d %s", $dates[$#dates]{year}, $dates[$#dates]{month}, $dates[$#dates]{day}, $dates[$#dates]{hour}, $dates[$#dates]{minute}, $dates[$#dates]{second}, $dates[$#dates]{time_zone}) . 
     82    ' is the future from ' . 
     83    sprintf("%04d-%02d-%02d %02d:%02d:%02d %s", $dates[0]{year}, $dates[0]{month}, $dates[0]{day}, $dates[0]{hour}, $dates[0]{minute}, $dates[0]{second}, $dates[0]{time_zone}) 
     84); 
     85ok( ($dt1->compare(b => { value => $dt2, type => 'datetime' }) < 0), 
     86    sprintf("%04d-%02d-%02d %02d:%02d:%02d %s", $dates[0]{year}, $dates[0]{month}, $dates[0]{day}, $dates[0]{hour}, $dates[0]{minute}, $dates[0]{second}, $dates[0]{time_zone}) . 
     87    ' is the past from ' . 
     88    sprintf("%04d-%02d-%02d %02d:%02d:%02d %s", $dates[$#dates]{year}, $dates[$#dates]{month}, $dates[$#dates]{day}, $dates[$#dates]{hour}, $dates[$#dates]{minute}, $dates[$#dates]{second}, $dates[$#dates]{time_zone}) 
     89);