Annotation of embedaddon/php/ext/date/tests/rfc-datetime_and_daylight_saving_time-type1.phpt, revision 1.1.1.1

1.1       misho       1: --TEST--
                      2: RFC: DateTime and Daylight Saving Time Transitions (zone type 1)
                      3: --CREDITS--
                      4: Daniel Convissor <danielc@php.net>
                      5: --FILE--
                      6: <?php
                      7: 
                      8: date_default_timezone_set('America/New_York');
                      9: $date_format = 'Y-m-d H:i:s e';
                     10: $interval_format = 'P%dDT%hH';
                     11: 
                     12: /*
                     13:  * Forward Transitions, diff().
                     14:  */
                     15: 
                     16: $end   = new DateTime('2010-03-14 03:00:00 -0400');
                     17: $start = new DateTime('2010-03-14 01:59:59 -0500');
                     18: echo 'fd1 ' . $end->format($date_format) . ' - ' . $start->format($date_format)
                     19:        . ' = ' . $start->diff($end)->format('PT%hH%iM%sS') . "\n";
                     20: 
                     21: $end   = new DateTime('2010-03-14 04:30:00 -0400');
                     22: $start = new DateTime('2010-03-13 04:30:00 -0500');
                     23: echo 'fd2 ' . $end->format($date_format) . ' - ' . $start->format($date_format)
                     24:        . ' = ' . $start->diff($end)->format($interval_format) . "\n";
                     25: 
                     26: $end   = new DateTime('2010-03-14 03:30:00 -0400');
                     27: $start = new DateTime('2010-03-13 04:30:00 -0500');
                     28: echo 'fd3 ' . $end->format($date_format) . ' - ' . $start->format($date_format)
                     29:        . ' = ' . $start->diff($end)->format($interval_format) . "\n";
                     30: 
                     31: $end   = new DateTime('2010-03-14 01:30:00 -0500');
                     32: $start = new DateTime('2010-03-13 04:30:00 -0500');
                     33: echo 'fd4 ' . $end->format($date_format) . ' - ' . $start->format($date_format)
                     34:        . ' = ' . $start->diff($end)->format($interval_format) . "\n";
                     35: 
                     36: $end   = new DateTime('2010-03-14 01:30:00 -0500');
                     37: $start = new DateTime('2010-03-13 01:30:00 -0500');
                     38: echo 'fd5 ' . $end->format($date_format) . ' - ' . $start->format($date_format)
                     39:        . ' = ' . $start->diff($end)->format($interval_format) . "\n";
                     40: 
                     41: $end   = new DateTime('2010-03-14 03:30:00 -0400');
                     42: $start = new DateTime('2010-03-13 03:30:00 -0500');
                     43: echo 'fd6 ' . $end->format($date_format) . ' - ' . $start->format($date_format)
                     44:        . ' = ' . $start->diff($end)->format($interval_format) . "\n";
                     45: 
                     46: $end   = new DateTime('2010-03-14 03:30:00 -0400');
                     47: $start = new DateTime('2010-03-13 02:30:00 -0500');
                     48: echo 'fd7 ' . $end->format($date_format) . ' - ' . $start->format($date_format)
                     49:        . ' = ' . $start->diff($end)->format($interval_format) . "\n";
                     50: 
                     51: echo "\n";
                     52: 
                     53: /*
                     54:  * Forward Transitions, add().
                     55:  */
                     56: 
                     57: $start = new DateTime('2010-03-14 01:59:59 -0500');
                     58: $interval_spec = 'PT1S';
                     59: $interval = new DateInterval($interval_spec);
                     60: echo 'fa1 ' . $start->format($date_format) . " + $interval_spec = "
                     61:        . $start->add($interval)->format($date_format) . "\n";
                     62: 
                     63: $start = new DateTime('2010-03-13 04:30:00 -0500');
                     64: $interval_spec = 'P1D';
                     65: $interval = new DateInterval($interval_spec);
                     66: echo 'fa2 ' . $start->format($date_format) . " + $interval_spec = "
                     67:        . $start->add($interval)->format($date_format) . "\n";
                     68: 
                     69: $start = new DateTime('2010-03-13 04:30:00 -0500');
                     70: $interval_spec = 'PT22H';
                     71: $interval = new DateInterval($interval_spec);
                     72: echo 'fa3 ' . $start->format($date_format) . " + $interval_spec = "
                     73:        . $start->add($interval)->format($date_format) . "\n";
                     74: 
                     75: $start = new DateTime('2010-03-13 04:30:00 -0500');
                     76: $interval_spec = 'PT21H';
                     77: $interval = new DateInterval($interval_spec);
                     78: echo 'fa4 ' . $start->format($date_format) . " + $interval_spec = "
                     79:        . $start->add($interval)->format($date_format) . "\n";
                     80: 
                     81: $start = new DateTime('2010-03-13 01:30:00 -0500');
                     82: $interval_spec = 'P1D';
                     83: $interval = new DateInterval($interval_spec);
                     84: echo 'fa5 ' . $start->format($date_format) . " + $interval_spec = "
                     85:        . $start->add($interval)->format($date_format) . "\n";
                     86: 
                     87: $start = new DateTime('2010-03-13 02:30:00 -0500');
                     88: $interval_spec = 'P1D';
                     89: $interval = new DateInterval($interval_spec);
                     90: echo 'fa6 ' . $start->format($date_format) . " + $interval_spec = "
                     91:        . $start->add($interval)->format($date_format) . "\n";
                     92: 
                     93: echo "\n";
                     94: 
                     95: /*
                     96:  * Forward Transitions, sub().
                     97:  */
                     98: 
                     99: $end   = new DateTime('2010-03-14 03:00:00 -0400');
                    100: $interval_spec = 'PT1S';
                    101: $interval = new DateInterval($interval_spec);
                    102: echo 'fs1 ' . $end->format($date_format) . " - $interval_spec = "
                    103:        . $end->sub($interval)->format($date_format) . "\n";
                    104: 
                    105: $end   = new DateTime('2010-03-14 04:30:00 -0400');
                    106: $interval_spec = 'P1D';
                    107: $interval = new DateInterval($interval_spec);
                    108: echo 'fs2 ' . $end->format($date_format) . " - $interval_spec = "
                    109:        . $end->sub($interval)->format($date_format) . "\n";
                    110: 
                    111: $end   = new DateTime('2010-03-14 03:30:00 -0400');
                    112: $interval_spec = 'PT22H';
                    113: $interval = new DateInterval($interval_spec);
                    114: echo 'fs3 ' . $end->format($date_format) . " - $interval_spec = "
                    115:        . $end->sub($interval)->format($date_format) . "\n";
                    116: 
                    117: $end   = new DateTime('2010-03-14 01:30:00 -0500');
                    118: $interval_spec = 'PT21H';
                    119: $interval = new DateInterval($interval_spec);
                    120: echo 'fs4 ' . $end->format($date_format) . " - $interval_spec = "
                    121:        . $end->sub($interval)->format($date_format) . "\n";
                    122: 
                    123: $end   = new DateTime('2010-03-14 01:30:00 -0500');
                    124: $interval_spec = 'P1D';
                    125: $interval = new DateInterval($interval_spec);
                    126: echo 'fs5 ' . $end->format($date_format) . " - $interval_spec = "
                    127:        . $end->sub($interval)->format($date_format) . "\n";
                    128: 
                    129: $end   = new DateTime('2010-03-15 03:30:00 -0400');
                    130: $interval_spec = 'P1D';
                    131: $interval = new DateInterval($interval_spec);
                    132: echo 'fs6 ' . $end->format($date_format) . " - $interval_spec = "
                    133:        . $end->sub($interval)->format($date_format) . "\n";
                    134: 
                    135: $end   = new DateTime('2010-03-15 02:30:00 -0400');
                    136: $interval_spec = 'P1D';
                    137: $interval = new DateInterval($interval_spec);
                    138: echo 'fs7 ' . $end->format($date_format) . " - $interval_spec = "
                    139:        . $end->sub($interval)->format($date_format) . "\n";
                    140: 
                    141: echo "\n";
                    142: 
                    143: /*
                    144:  * Backward Transitions, diff().
                    145:  */
                    146: 
                    147: $end   = new DateTime('2010-11-07 01:00:00 -0500');
                    148: $start = new DateTime('2010-11-07 01:59:59 -0400');
                    149: echo 'bd1 ' . $end->format($date_format) . ' - ' . $start->format($date_format)
                    150:        . ' = ' . $start->diff($end)->format('PT%hH%iM%sS') . "\n";
                    151: 
                    152: $end   = new DateTime('2010-11-07 04:30:00 -0500');
                    153: $start = new DateTime('2010-11-06 04:30:00 -0400');
                    154: echo 'bd2 ' . $end->format($date_format) . ' - ' . $start->format($date_format)
                    155:        . ' = ' . $start->diff($end)->format($interval_format) . "\n";
                    156: 
                    157: $end   = new DateTime('2010-11-07 03:30:00 -0500');
                    158: $start = new DateTime('2010-11-06 04:30:00 -0400');
                    159: echo 'bd3 ' . $end->format($date_format) . ' - ' . $start->format($date_format)
                    160:        . ' = ' . $start->diff($end)->format($interval_format) . "\n";
                    161: 
                    162: $end   = new DateTime('2010-11-07 02:30:00 -0500');
                    163: $start = new DateTime('2010-11-06 04:30:00 -0400');
                    164: echo 'bd4 ' . $end->format($date_format) . ' - ' . $start->format($date_format)
                    165:        . ' = ' . $start->diff($end)->format($interval_format) . "\n";
                    166: 
                    167: $end   = new DateTime('2010-11-07 01:30:00 -0500');
                    168: $start = new DateTime('2010-11-06 04:30:00 -0400');
                    169: echo 'bd5 ' . $end->format($date_format) . ' - ' . $start->format($date_format)
                    170:        . ' = ' . $start->diff($end)->format($interval_format) . "\n";
                    171: 
                    172: $end   = new DateTime('2010-11-07 01:30:00 -0400');
                    173: $start = new DateTime('2010-11-06 04:30:00 -0400');
                    174: echo 'bd6 ' . $end->format($date_format) . ' - ' . $start->format($date_format)
                    175:        . ' = ' . $start->diff($end)->format($interval_format) . "\n";
                    176: 
                    177: $end   = new DateTime('2010-11-07 01:30:00 -0400');
                    178: $start = new DateTime('2010-11-06 01:30:00 -0400');
                    179: echo 'bd7 ' . $end->format($date_format) . ' - ' . $start->format($date_format)
                    180:        . ' = ' . $start->diff($end)->format($interval_format) . "\n";
                    181: 
                    182: $end   = new DateTime('2010-11-07 01:30:00 -0500');
                    183: $start = new DateTime('2010-11-06 01:30:00 -0400');
                    184: echo 'bd8 ' . $end->format($date_format) . ' - ' . $start->format($date_format)
                    185:        . ' = ' . $start->diff($end)->format($interval_format) . "\n";
                    186: 
                    187: echo "\n";
                    188: 
                    189: /*
                    190:  * Backward Transitions, add().
                    191:  */
                    192: 
                    193: $start = new DateTime('2010-11-07 01:59:59 -0400');
                    194: $interval_spec = 'PT1S';
                    195: $interval = new DateInterval($interval_spec);
                    196: echo 'ba1 ' . $start->format($date_format) . " + $interval_spec = "
                    197:        . $start->add($interval)->format($date_format) . "\n";
                    198: 
                    199: $start = new DateTime('2010-11-06 04:30:00 -0400');
                    200: $interval_spec = 'P1D';
                    201: $interval = new DateInterval($interval_spec);
                    202: echo 'ba2 ' . $start->format($date_format) . " + $interval_spec = "
                    203:        . $start->add($interval)->format($date_format) . "\n";
                    204: 
                    205: $start = new DateTime('2010-11-06 04:30:00 -0400');
                    206: $interval_spec = 'PT24H';
                    207: $interval = new DateInterval($interval_spec);
                    208: echo 'ba3 ' . $start->format($date_format) . " + $interval_spec = "
                    209:        . $start->add($interval)->format($date_format) . "\n";
                    210: 
                    211: $start = new DateTime('2010-11-06 04:30:00 -0400');
                    212: $interval_spec = 'PT23H';
                    213: $interval = new DateInterval($interval_spec);
                    214: echo 'ba4 ' . $start->format($date_format) . " + $interval_spec = "
                    215:        . $start->add($interval)->format($date_format) . "\n";
                    216: 
                    217: $start = new DateTime('2010-11-06 04:30:00 -0400');
                    218: $interval_spec = 'PT22H';
                    219: $interval = new DateInterval($interval_spec);
                    220: echo 'ba5 ' . $start->format($date_format) . " + $interval_spec = "
                    221:        . $start->add($interval)->format($date_format) . "\n";
                    222: 
                    223: $start = new DateTime('2010-11-06 04:30:00 -0400');
                    224: $interval_spec = 'PT21H';
                    225: $interval = new DateInterval($interval_spec);
                    226: echo 'ba6 ' . $start->format($date_format) . " + $interval_spec = "
                    227:        . $start->add($interval)->format($date_format) . "\n";
                    228: 
                    229: $start = new DateTime('2010-11-06 01:30:00 -0400');
                    230: $interval_spec = 'P1D';
                    231: $interval = new DateInterval($interval_spec);
                    232: echo 'ba7 ' . $start->format($date_format) . " + $interval_spec = "
                    233:        . $start->add($interval)->format($date_format) . "\n";
                    234: 
                    235: $start = new DateTime('2010-11-06 01:30:00 -0400');
                    236: $interval_spec = 'P1DT1H';
                    237: $interval = new DateInterval($interval_spec);
                    238: echo 'ba8 ' . $start->format($date_format) . " + $interval_spec = "
                    239:        . $start->add($interval)->format($date_format) . "\n";
                    240: 
                    241: $start = new DateTime('2010-11-06 04:30:00 -0400');
                    242: $interval_spec = 'PT25H';
                    243: $interval = new DateInterval($interval_spec);
                    244: echo 'ba9 ' . $start->format($date_format) . " + $interval_spec = "
                    245:        . $start->add($interval)->format($date_format) . "\n";
                    246: 
                    247: $start = new DateTime('2010-11-06 03:30:00 -0400');
                    248: $interval_spec = 'P1D';
                    249: $interval = new DateInterval($interval_spec);
                    250: echo 'ba10 ' . $start->format($date_format) . " + $interval_spec = "
                    251:        . $start->add($interval)->format($date_format) . "\n";
                    252: 
                    253: $start = new DateTime('2010-11-06 02:30:00 -0400');
                    254: $interval_spec = 'P1D';
                    255: $interval = new DateInterval($interval_spec);
                    256: echo 'ba11 ' . $start->format($date_format) . " + $interval_spec = "
                    257:        . $start->add($interval)->format($date_format) . "\n";
                    258: 
                    259: echo "\n";
                    260: 
                    261: /*
                    262:  * Backward Transitions, sub().
                    263:  */
                    264: 
                    265: $end   = new DateTime('2010-11-07 01:00:00 -0500');
                    266: $interval_spec = 'PT1S';
                    267: $interval = new DateInterval($interval_spec);
                    268: echo 'bs1 ' . $end->format($date_format) . " - $interval_spec = "
                    269:        . $end->sub($interval)->format($date_format) . "\n";
                    270: 
                    271: $end   = new DateTime('2010-11-07 04:30:00 -0500');
                    272: $interval_spec = 'P1D';
                    273: $interval = new DateInterval($interval_spec);
                    274: echo 'bs2 ' . $end->format($date_format) . " - $interval_spec = "
                    275:        . $end->sub($interval)->format($date_format) . "\n";
                    276: 
                    277: $end   = new DateTime('2010-11-07 03:30:00 -0500');
                    278: $interval_spec = 'PT24H';
                    279: $interval = new DateInterval($interval_spec);
                    280: echo 'bs3 ' . $end->format($date_format) . " - $interval_spec = "
                    281:        . $end->sub($interval)->format($date_format) . "\n";
                    282: 
                    283: $end   = new DateTime('2010-11-07 02:30:00 -0500');
                    284: $interval_spec = 'PT23H';
                    285: $interval = new DateInterval($interval_spec);
                    286: echo 'bs4 ' . $end->format($date_format) . " - $interval_spec = "
                    287:        . $end->sub($interval)->format($date_format) . "\n";
                    288: 
                    289: $end   = new DateTime('2010-11-07 01:30:00 -0500');
                    290: $interval_spec = 'PT22H';
                    291: $interval = new DateInterval($interval_spec);
                    292: echo 'bs5 ' . $end->format($date_format) . " - $interval_spec = "
                    293:        . $end->sub($interval)->format($date_format) . "\n";
                    294: 
                    295: $end   = new DateTime('2010-11-07 01:30:00 -0400');
                    296: $interval_spec = 'PT21H';
                    297: $interval = new DateInterval($interval_spec);
                    298: echo 'bs6 ' . $end->format($date_format) . " - $interval_spec = "
                    299:        . $end->sub($interval)->format($date_format) . "\n";
                    300: 
                    301: $end   = new DateTime('2010-11-07 01:30:00 -0400');
                    302: $interval_spec = 'P1D';
                    303: $interval = new DateInterval($interval_spec);
                    304: echo 'bs7 ' . $end->format($date_format) . " - $interval_spec = "
                    305:        . $end->sub($interval)->format($date_format) . "\n";
                    306: 
                    307: $end   = new DateTime('2010-11-07 01:30:00 -0500');
                    308: $interval_spec = 'P1DT1H';
                    309: $interval = new DateInterval($interval_spec);
                    310: echo 'bs8 ' . $end->format($date_format) . " - $interval_spec = "
                    311:        . $end->sub($interval)->format($date_format) . "\n";
                    312: 
                    313: $end   = new DateTime('2010-11-07 03:30:00 -0500');
                    314: $interval_spec = 'P1D';
                    315: $interval = new DateInterval($interval_spec);
                    316: echo 'bs9 ' . $end->format($date_format) . " - $interval_spec = "
                    317:        . $end->sub($interval)->format($date_format) . "\n";
                    318: 
                    319: $end   = new DateTime('2010-11-07 02:30:00 -0500');
                    320: $interval_spec = 'P1D';
                    321: $interval = new DateInterval($interval_spec);
                    322: echo 'bs10 ' . $end->format($date_format) . " - $interval_spec = "
                    323:        . $end->sub($interval)->format($date_format) . "\n";
                    324: 
                    325: ?>
                    326: --EXPECT--
                    327: fd1 2010-03-14 03:00:00 -04:00 - 2010-03-14 01:59:59 -05:00 = PT0H0M1S
                    328: fd2 2010-03-14 04:30:00 -04:00 - 2010-03-13 04:30:00 -05:00 = P0DT23H
                    329: fd3 2010-03-14 03:30:00 -04:00 - 2010-03-13 04:30:00 -05:00 = P0DT22H
                    330: fd4 2010-03-14 01:30:00 -05:00 - 2010-03-13 04:30:00 -05:00 = P0DT21H
                    331: fd5 2010-03-14 01:30:00 -05:00 - 2010-03-13 01:30:00 -05:00 = P1DT0H
                    332: fd6 2010-03-14 03:30:00 -04:00 - 2010-03-13 03:30:00 -05:00 = P0DT23H
                    333: fd7 2010-03-14 03:30:00 -04:00 - 2010-03-13 02:30:00 -05:00 = P1DT0H
                    334: 
                    335: fa1 2010-03-14 01:59:59 -05:00 + PT1S = 2010-03-14 02:00:00 -05:00
                    336: fa2 2010-03-13 04:30:00 -05:00 + P1D = 2010-03-14 04:30:00 -05:00
                    337: fa3 2010-03-13 04:30:00 -05:00 + PT22H = 2010-03-14 02:30:00 -05:00
                    338: fa4 2010-03-13 04:30:00 -05:00 + PT21H = 2010-03-14 01:30:00 -05:00
                    339: fa5 2010-03-13 01:30:00 -05:00 + P1D = 2010-03-14 01:30:00 -05:00
                    340: fa6 2010-03-13 02:30:00 -05:00 + P1D = 2010-03-14 02:30:00 -05:00
                    341: 
                    342: fs1 2010-03-14 03:00:00 -04:00 - PT1S = 2010-03-14 02:59:59 -04:00
                    343: fs2 2010-03-14 04:30:00 -04:00 - P1D = 2010-03-13 04:30:00 -04:00
                    344: fs3 2010-03-14 03:30:00 -04:00 - PT22H = 2010-03-13 05:30:00 -04:00
                    345: fs4 2010-03-14 01:30:00 -05:00 - PT21H = 2010-03-13 04:30:00 -05:00
                    346: fs5 2010-03-14 01:30:00 -05:00 - P1D = 2010-03-13 01:30:00 -05:00
                    347: fs6 2010-03-15 03:30:00 -04:00 - P1D = 2010-03-14 03:30:00 -04:00
                    348: fs7 2010-03-15 02:30:00 -04:00 - P1D = 2010-03-14 02:30:00 -04:00
                    349: 
                    350: bd1 2010-11-07 01:00:00 -05:00 - 2010-11-07 01:59:59 -04:00 = PT0H0M1S
                    351: bd2 2010-11-07 04:30:00 -05:00 - 2010-11-06 04:30:00 -04:00 = P1DT1H
                    352: bd3 2010-11-07 03:30:00 -05:00 - 2010-11-06 04:30:00 -04:00 = P1DT0H
                    353: bd4 2010-11-07 02:30:00 -05:00 - 2010-11-06 04:30:00 -04:00 = P0DT23H
                    354: bd5 2010-11-07 01:30:00 -05:00 - 2010-11-06 04:30:00 -04:00 = P0DT22H
                    355: bd6 2010-11-07 01:30:00 -04:00 - 2010-11-06 04:30:00 -04:00 = P0DT21H
                    356: bd7 2010-11-07 01:30:00 -04:00 - 2010-11-06 01:30:00 -04:00 = P1DT0H
                    357: bd8 2010-11-07 01:30:00 -05:00 - 2010-11-06 01:30:00 -04:00 = P1DT1H
                    358: 
                    359: ba1 2010-11-07 01:59:59 -04:00 + PT1S = 2010-11-07 02:00:00 -04:00
                    360: ba2 2010-11-06 04:30:00 -04:00 + P1D = 2010-11-07 04:30:00 -04:00
                    361: ba3 2010-11-06 04:30:00 -04:00 + PT24H = 2010-11-07 04:30:00 -04:00
                    362: ba4 2010-11-06 04:30:00 -04:00 + PT23H = 2010-11-07 03:30:00 -04:00
                    363: ba5 2010-11-06 04:30:00 -04:00 + PT22H = 2010-11-07 02:30:00 -04:00
                    364: ba6 2010-11-06 04:30:00 -04:00 + PT21H = 2010-11-07 01:30:00 -04:00
                    365: ba7 2010-11-06 01:30:00 -04:00 + P1D = 2010-11-07 01:30:00 -04:00
                    366: ba8 2010-11-06 01:30:00 -04:00 + P1DT1H = 2010-11-07 02:30:00 -04:00
                    367: ba9 2010-11-06 04:30:00 -04:00 + PT25H = 2010-11-07 05:30:00 -04:00
                    368: ba10 2010-11-06 03:30:00 -04:00 + P1D = 2010-11-07 03:30:00 -04:00
                    369: ba11 2010-11-06 02:30:00 -04:00 + P1D = 2010-11-07 02:30:00 -04:00
                    370: 
                    371: bs1 2010-11-07 01:00:00 -05:00 - PT1S = 2010-11-07 00:59:59 -05:00
                    372: bs2 2010-11-07 04:30:00 -05:00 - P1D = 2010-11-06 04:30:00 -05:00
                    373: bs3 2010-11-07 03:30:00 -05:00 - PT24H = 2010-11-06 03:30:00 -05:00
                    374: bs4 2010-11-07 02:30:00 -05:00 - PT23H = 2010-11-06 03:30:00 -05:00
                    375: bs5 2010-11-07 01:30:00 -05:00 - PT22H = 2010-11-06 03:30:00 -05:00
                    376: bs6 2010-11-07 01:30:00 -04:00 - PT21H = 2010-11-06 04:30:00 -04:00
                    377: bs7 2010-11-07 01:30:00 -04:00 - P1D = 2010-11-06 01:30:00 -04:00
                    378: bs8 2010-11-07 01:30:00 -05:00 - P1DT1H = 2010-11-06 00:30:00 -05:00
                    379: bs9 2010-11-07 03:30:00 -05:00 - P1D = 2010-11-06 03:30:00 -05:00
                    380: bs10 2010-11-07 02:30:00 -05:00 - P1D = 2010-11-06 02:30:00 -05:00

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>