Annotation of embedaddon/php/ext/date/tests/date_diff.phpt, revision 1.1
1.1 ! misho 1: --TEST--
! 2: Extensive test for date_diff().
! 3: --SKIPIF--
! 4: <?php
! 5: if (getenv("SKIP_SLOW_TESTS")) die("skip slow test");
! 6: ?>
! 7: --INI--
! 8: date.timezone=UTC
! 9: --FILE--
! 10: <?php
! 11: $ok = 0;
! 12: define( 'COUNT', 120 );
! 13: $d0 = new DateTime('2009-11-20');
! 14: for ( $i = 0; $i < COUNT * 12; $i++ )
! 15: {
! 16: $d = clone $d0;
! 17: $dates[$i] = $d->add( new DateInterval( "P{$i}D" ) );
! 18: }
! 19:
! 20: for ( $i = 0; $i < COUNT; $i++)
! 21: {
! 22: // echo $dates[$i]->format( "Y-m-d\n" );
! 23: for ( $j = 0; $j < COUNT * 12; $j++)
! 24: {
! 25: $diff = date_diff( $dates[$i], $dates[$j] );
! 26: /*
! 27: printf( "\t%s %s %3d %s\n",
! 28: $dates[$i]->format( 'Y-m-d' ),
! 29: $dates[$j]->format( 'Y-m-d' ),
! 30: $diff->format( '%a' ),
! 31: $diff->format( '%y-%m-%d' )
! 32: );
! 33: */
! 34:
! 35: $current = clone $dates[$i];
! 36: $int = new DateInterval( $diff->format( 'P%yY%mM%dD' ) );
! 37: if ( $current > $dates[$j] )
! 38: {
! 39: $current->sub( $int );
! 40: }
! 41: else
! 42: {
! 43: $current->add( $int );
! 44: }
! 45: if ( $current != $dates[$j] )
! 46: {
! 47: echo "FAIL: ",
! 48: $dates[$i]->format( 'Y-m-d' ), " + ",
! 49: $int->format( '%y-%m-%d' ), " = ",
! 50: $current->format( 'Y-m-d' ), " (",
! 51: $dates[$j]->format( 'Y-m-d' ), ")\n";
! 52: }
! 53: else
! 54: {
! 55: $ok++;
! 56: }
! 57: }
! 58: }
! 59:
! 60: echo $ok, "\n";
! 61: ?>
! 62: --EXPECT--
! 63: 172800
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>