1 (*i $Id: test_date.ml,v 1.21 2008/02/08 13:06:45 signoles Exp $ i*)
3 Printf.printf "Tests of Date:\n";;
10 test_exn (lazy (make (-4713) 1 1)) "make (-4713) 1 1";;
11 test_exn (lazy (make 3268 1 23)) "make 3268 1 23";;
12 test_exn (lazy (make 1582 10 5)) "make 1582 10 10";;
13 test (compare (make 2003 2 29) (make 2003 3 1) = 0) "2003-2-29 = 2003-3-1";;
14 let d = make 2003 12 31;;
15 test (next d `Month = make 2004 1 31) "2003-12-31 + 1 mois";;
16 test (add d (Period.month 2) = make 2004 3 2) "2003-12-31 + 2 mois";;
17 let d2 = make (-3000) 1 1;;
18 test (rem d (sub d d2) = d2) "rem x (sub x y) = y";;
19 test (from_jd 0 = make (-4712) 1 1) "from_jd 0 = 4713 BC-1-1";;
20 test (to_jd (from_jd 12345) = 12345) "to_jd (from_jd x) = x";;
21 test (from_mjd 0 = make 1858 11 17) "from_mjd 0 = 1858-11-17";;
22 test (to_mjd (from_mjd 12345) = 12345) "to_mjd (from_mjd x) = x";;
23 test (is_leap_day (make 2000 2 24)) "2000-2-24 leap day";;
24 test (not (is_leap_day (make 2000 2 25))) "2000-2-25 not leap day";;
25 test (is_gregorian (make 1600 1 1)) "1600-1-1 gregorian";;
26 test (not (is_gregorian (make 1400 1 1))) "1400-1-1 not gregorian";;
27 test (is_julian (make 1582 1 1)) "1582-1-1 julian";;
28 test (not (is_julian (make 1583 1 1))) "1583-1-1 not julian";;
29 test (int_of_day Mon = 1) "Monday = 1";;
30 test (int_of_day Sun = 7) "Sunday = 7";;
31 test (day_of_int 1 = Mon) "1 = Monday";;
32 test (day_of_int 7 = Sun) "1 = Monday";;
33 test (int_of_month Jan = 1) "January = 1";;
34 test (month_of_int 12 = Dec) "12 = December";;
35 test (not (is_leap_year 1999)) "1999 not leap year";;
36 test (not (is_leap_year 1800)) "1800 not leap year";;
37 test (is_leap_year 1996) "1996 leap year";;
38 test (is_leap_year 1600) "1600 leap year";;
39 test (same_calendar 1956 1900) "same calendar 1956 1900";;
40 test (same_calendar 2001 2013) "same calendar 2001 2013";;
41 test (same_calendar 1998 2009) "same calendar 1998 2009";;
42 test (same_calendar 2003 2025) "same calendar 2003 2025";;
43 test (days_in_year 2000 = 366) "days_in_year 2000";;
44 test (days_in_year 1900 = 365) "days_in_year 1900";;
45 test (days_in_year ~month:Jan 2000 = 31) "days_in_year Jan 2000";;
46 test (days_in_year ~month:Feb 2000 = 60) "days_in_year Feb 2000";;
47 test (days_in_year ~month:Jan 2000 = 31) "days_in_year Jan 2000";;
48 test (days_in_year ~month:Mar 1900 = 90) "days_in_year Mar 1900";;
49 test (weeks_in_year 2000 = 52) "weeks_in_year 2000";;
50 test (weeks_in_year 2020 = 53) "weeks_in_year 2020";;
51 test (weeks_in_year 1991 = 52) "weeks_in_year 1991";;
52 test (weeks_in_year 1999 = 52) "weeks_in_year 1999";;
53 test (century 2000 = 20) "century 2000";;
54 test (century 2001 = 21) "century 2001";;
55 test (millenium 2000 = 2) "millenium 2000";;
56 test (millenium 2001 = 3) "millenium 2001";;
57 test (easter 2003 = make 2003 4 20) "Paques 2003";;
58 test (Period.nb_days (Period.make 0 0 6) = 6) "Period.nb_days ok";;
59 test_exn (lazy (Period.nb_days (Period.make 1 0 0))) "Period.nb_days ko";;
60 test (week_first_last 21 2004 = (make 2004 5 17, make 2004 5 23))
61 "week_beggining_end";;
62 test (Period.ymd (Period.make 1 2 3) = (1, 2, 3)) "Period.ymd";;
63 test (nth_weekday_of_month 2004 Oct Thu 4 = make 2004 10 28)
64 "nth_weekday_of_month";;
65 test (nth_weekday_of_month 2006 Mar Fri 3 = make 2006 3 17)
66 "nth_weekday_of_month";;
67 test (equal (from_day_of_year 2008 39) (make 2008 2 8))
69 test (is_valid_date 2008 2 8) "is_valid_date";;
70 test (not (is_valid_date 2008 2 30)) "not is_valid_date";;
73 Time_Zone.change Time_Zone.UTC;;
74 test (to_unixfloat (make 1970 1 1) = 0.) "to_unixfloat 1 Jan 1970";;
75 test (from_unixfloat 0. = make 1970 1 1) "from_unixfloat 0.";;
76 test (to_unixfloat (make 2004 11 13) = 1100304000.) "to_unixfloat";;
77 test (from_unixfloat 1100304000. = make 2004 11 13) "from_unixfloat";;
78 test (from_unixtm (to_unixtm (make 2003 7 16)) = make 2003 7 16)
79 "from_unixtm to_unixtm = id";;
80 Time_Zone.change (Time_Zone.UTC_Plus (-1));;
81 test (from_unixfloat 0. = make 1969 12 31) "from_unixfloat 0. (dec-)";;
82 test (from_unixtm { Unix.tm_sec = 0; tm_min = 0; tm_hour = 0; tm_mday = 1;
83 tm_mon = 0; tm_year = 70; tm_wday = 4; tm_yday = 0;
84 tm_isdst = false } = make 1969 12 31)
85 "from_unixtm (dec-)";;
86 Time_Zone.change (Time_Zone.UTC_Plus 1);;
87 test (from_unixfloat 1100390390. = make 2004 11 14) "from_unixfloat (dec+)";;
88 test (from_unixtm { Unix.tm_sec = 0; tm_min = 0; tm_hour = 0; tm_mday = 14;
89 tm_mon = 10; tm_year = 104; tm_wday = 0; tm_yday = 318;
90 tm_isdst = false } = make 2004 11 14)
91 "from_unixtm (dec+)";;
92 test (from_unixtm (to_unixtm (make 2003 7 16)) = make 2003 7 16)
93 "from_unixtm to_unixtm = id";;
96 test (to_business (make 2003 1 1) = (2003, 1, Wed)) "to_business 1";;
97 test (to_business (make 2003 12 31) = (2004, 1, Wed)) "to_business 2";;
98 test (to_business (make 2002 12 31) = (2003, 1, Tue)) "to_business 3";;
99 test (to_business (make 2005 1 1) = (2004, 53, Sat)) "to_business 4";;
100 test (to_business (make 2004 12 31) = (2004, 53, Fri)) "to_business 5";;
101 test (to_business (make 2006 1 1) = (2005, 52, Sun)) "to_business 6";;
102 test (to_business (make 2005 1 17) = (2005, 3, Mon)) "to_business 7";;
103 test (to_business (make 2006 1 31) = (2006, 5, Tue)) "to_business 8";;
104 test (to_business (make 2005 1 31) = (2005, 5, Mon)) "to_business 9";;
106 test (from_business 2003 1 Wed = make 2003 1 1) "from_business 1";;
107 test (from_business 2004 1 Wed = make 2003 12 31) "from_business 2";;
108 test (from_business 2003 1 Tue = make 2002 12 31) "from_business 3";;
109 test (from_business 2004 53 Sat = make 2005 1 1) "from_business 4";;
110 test (from_business 2004 53 Fri = make 2004 12 31) "from_business 5";;
111 test (from_business 2005 52 Sun = make 2006 1 1) "from_business 6";;
112 test (from_business 2005 3 Mon = make 2005 1 17) "from_business 7";;
113 test (from_business 2006 5 Tue = make 2006 1 31) "from_business 8";;
114 test (from_business 2005 5 Mon = make 2005 1 31) "from_business 9";;
115 test_exn (lazy (from_business 2005 0 Sun)) "from_business_bad 1";;
116 test_exn (lazy (from_business 2005 53 Sun)) "from_business_bad 2";;
119 let bug = nb_bug ();;
120 Printf.printf "tests ok : %d; tests ko : %d\n" ok bug;;