File: test_calc.php

package info (click to toggle)
php-date 1.4.7-1
  • links: PTS
  • area: main
  • in suites: lenny, squeeze, wheezy
  • size: 508 kB
  • ctags: 697
  • sloc: php: 7,202; xml: 320; makefile: 50
file content (46 lines) | stat: -rw-r--r-- 1,346 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
<?php
require_once "Date/Calc.php";

/**
 * Test dates from 1970 to 2029
 * Data from: http://www.merlyn.demon.co.uk/wknotest.txt
 * Others usefull datas available from:
 * http://www.merlyn.demon.co.uk/#dat
 */
$failed_test_data   = false;
$wkno   = file('wknotest.txt');
$cnt    = sizeof($wkno);
for( $i=0;$i<$cnt;$i++ ){
    $parts      = explode(':',$wkno[$i]);
    $weeksno[$parts[0]] = str_replace("\n",'',$parts[1]);
}
unset($wkno);
foreach($weeksno as $date=>$iso){
    $year       = substr($date,0,4);
    $month      = substr($date,4,2);
    $day        = substr($date,6);
    $iso9601 = Date_Calc::gregorianToISO($day,$month,$year);
    if($iso9601!=$iso){
        $failed_test_data   = true;
        echo $date . '(' . $iso . ') =>' . $year.'-'.$month.'-'.$day .'=>' . $iso9601 . " : failed\n";
    }
}

/**
 * Bugs #19788
 */
$failed_test_19788  = false;
$pass1  = 2==Date_Calc::weekOfYear(5,1,1998)?true:false;
$pass2  = 2==Date_Calc::weekOfYear(6,1,1998)?true:false;
$pass3  = 2==Date_Calc::weekOfYear(5,1,2004)?true:false;
$pass4  = 2==Date_Calc::weekOfYear(6,1,2004)?true:false;
if( !($pass1 && $pass2 && $pass3 && $pass4) ){
    $failed_test_19788   = true;
}

if($failed_test_19788 || $failed_test_data){
    echo "Bug #19788: failed\n";
} else {
    echo "Bug #19788: OK\n";
}
?>