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
  
47
  
48
  
49
  
50
  
51
  
52
  
53
  
54
  
55
  
56
  
57
  
58
  
59
  
60
  
61
  
62
  
63
  
64
  
65
  
66
  
67
  
68
  
69
  
70
  
71
  
72
  
73
  
74
  
75
  
76
  
77
  
78
  
79
  
80
  
81
  
82
  
83
  
84
  
85
  
86
  
87
  
88
  
89
  
90
  
91
  
92
  
93
  
94
  
95
  
96
  
97
  
98
  
99
  
100
  
101
  
102
  
103
  
104
  
105
  
106
  
107
  
108
  
109
  
110
  
111
  
112
  
113
  
114
  
115
  
116
  
117
  
118
  
119
  
120
  
121
  
122
  
123
  
124
  
125
  
126
  
127
  
128
  
129
  
130
  
131
  
132
  
133
  
134
  
135
  
136
  
137
  
138
  
139
  
140
  
141
  
142
  
143
  
144
  
145
  
146
  
147
  
148
  
149
  
150
  
151
  
152
  
153
  
154
  
155
  
156
  
157
  
158
  
159
  
160
  
161
  
162
  
163
  
164
  
165
  
166
  
167
  
168
  
169
  
170
  
171
  
172
  
173
  
174
  
175
  
176
  
177
  
178
  
179
  
180
  
181
  
182
  
183
  
184
  
185
  
186
  
187
  
188
  
189
  
190
  
191
  
192
  
193
  
194
  
195
  
196
  
197
  
198
  
199
  
200
  
201
  
202
  
203
  
204
  
205
  
206
  
207
  
208
  
209
  
210
  
211
  
212
  
213
  
214
  
215
  
216
  
217
  
218
  
219
  
220
  
221
  
222
  
223
  
224
  
225
  
226
  
227
  
228
  
229
  
230
  
231
  
232
  
233
  
234
  
235
  
236
  
237
  
dnl $Id: testsuite.in,v 1.14 2008/03/05 12:49:06 mast Exp $ 
 
dnl NOTE: 
dnl   *every* time the Calendar tests have failed, it's not the  
dnl   Calendar module that had any errors. Please don't commit  
dnl   your Pike until you've got Calendar to compile again. /Mirar 
 
test_true(Calendar.Day()) 
 
test_eq([[Calendar.Austrian.Day(2500000)->month_day()]],31) 
test_eq([[Calendar.Coptic.Day(2500000)->month_day()]],25); 
test_eq([[Calendar.Gregorian.Day(2500000)->month_day()]],31) 
test_eq([[Calendar.ISO.Day(2500000)->month_day()]],31) 
test_eq([[Calendar.Julian.Day(2500000)->month_day()]],17) 
test_eq([[(int)(Calendar.Stardate.Tick("julian",2500000)->tic())]],-190335) 
 
test_eq(Calendar.ISO.Week(2002,1)->day()->format_ymd(),"2001-12-31") 
 
test_eval_error(Calendar.ISO.set_timezone("Europe/Stockholm") 
                ->dwim_time("2000-03-26 02:01:17")) 
 
test_eq(Calendar.ISO_UTC.dwim_time("2000-03-26 02:01:17")->unix_time(), 
        954036077) 
 
test_do(Calendar.TimeRange t = Calendar.now()) 
 
dnl Some more or less odd timezones encountered by Xenofarm: 
define(test_dwim,[[ 
  test_eq(Calendar.ISO.set_timezone("CET")->dwim_time($1)->format_time(),"2002-11-19 07:04:03") 
  test_eq(Calendar.ISO.set_timezone("CET")->dwim_time($1)->tzname(),$2) 
]]) 
test_dwim("Tue Nov 19 07:04:03 MET 2002","MET") 
test_dwim("Tue Nov 19 07:04:03 CST 2002","CST") 
test_dwim("Tue Nov 19 07:04:03 CET 2002","CET") 
test_dwim("Tue Nov 19 07:04:03  2002","CET") 
test_dwim("Tue Nov 19 07:04:03 NFT 2002","NFT") 
dnl test_dwim("Tue Nov 19 07:04:03 DFT 2002","DFT") 
test_dwim("Tue Nov 19 07:04:03 MET DST 2002","MET") 
test_dwim("Tue Nov 19 07:04:03 METDST 2002","MET") 
 
test_eq(arrayp(Calendar.TZnames.zonenames()), 1) 
 
dnl FAQ tests 
test_eq( Calendar.dwim_day("1/2/3"), Calendar.Day(2003,1,2) ) 
test_eq( Calendar.dwim_day("1 aug 2001"), Calendar.Day(2001,8,1) ) 
test_false( Calendar.dwim_day("1 aug 2001")==Calendar.Day(2001,8,2) ) 
dnl Missing two dwim_time tests 
test_eq( Calendar.parse("%Y-%M-%D %h:%m","2040-11-08 2:46"), 
  Calendar.Minute(2040,11,8,2,46) ) 
test_false( Calendar.parse("%Y w%W %e %h:%m %p %z","1913 w4 monday 2:14 pm CET") 
  < Calendar.set_timezone("CET")->Minute(1913,1,20,14,14) ) 
test_false( Calendar.parse("%Y w%W %e %h:%m %p %z","1913 w4 monday 2:14 pm CET") 
  > Calendar.set_timezone("CET")->Minute(1913,1,20,14,14) ) 
dnl The two objects above is not equal, which really is a bug. 
 
 
dnl From verify.pike 
define(test_WDIFF,[[ 
test_true( $1->week_no() == $2->week_no() ) 
test_true( $1->week() == $2->week() ) 
test_true( $1->week()->year() == $2->week()->year() ) 
]]) 
define(test_day,[[ 
test_do([[ 
  sscanf($1,"%d-%d-%d %s %dw%d", 
         int y,int m,int d,string wd,int wy,int w); 
  add_constant("d1", Calendar.ISO.Day(y,m,d)); 
  add_constant("d2", Calendar.ISO.dwim_day(y+"-"+m+"-"+d)); 
  add_constant("d3", Calendar.ISO.Week(wy,w)->day(wd)); 
]]) 
test_true( objectp(d1) ) 
test_true( objectp(d2) ) 
test_true( objectp(d3) ) 
test_true( d1==d2 ) 
test_true( d2==d3 ) 
test_true( d3==d1 ) 
test_WDIFF(d1,d2) 
test_WDIFF(d2,d3) 
test_WDIFF(d3,d1) 
test_any([[ 
  sscanf($1,"%d-%d-%d %s %dw%d", 
         int y,int m,int d,string wd,int wy,int w); 
  return w; 
]], d1->week_no()) 
test_any([[ 
  sscanf($1,"%d-%d-%d %s %dw%d", 
         int y,int m,int d,string wd,int wy,int w); 
  return wy; 
]], d1->week()->year_no()) 
test_do([[ add_constant("d1"); ]]) 
test_do([[ add_constant("d2"); ]]) 
test_do([[ add_constant("d3"); ]]) 
]]) 
test_day("1993-12-31 Fri 1993w52") 
test_day("1994-01-01 Sat 1993w52") 
test_day("1994-12-31 Sat 1994w52") 
test_day("1995-01-01 Sun 1994w52") 
test_day("1995-12-31 Sun 1995w52") 
test_day("1996-01-01 Mon 1996w01") 
test_day("1996-12-31 Tue 1997w01") 
test_day("1997-01-01 Wed 1997w01") 
test_day("1997-12-31 Wed 1998w01") 
test_day("1998-01-01 Thu 1998w01") 
test_day("1998-12-31 Thu 1998w53") 
test_day("1999-01-01 Fri 1998w53") 
test_day("1999-12-31 Fri 1999w52") 
test_day("2000-01-01 Sat 1999w52") 
test_day("2000-12-31 Sun 2000w52") 
test_day("2001-01-01 Mon 2001w01") 
 
test_day("2003-12-31 Wed 2004w01") 
test_day("2004-01-01 Thu 2004w01") 
 
test_eq([[ Calendar.ISO.Week(2001, 1)->format_ymd() ]], "2001-01-01") 
test_eq([[ Calendar.ISO.Week(2002, 1)->format_ymd() ]], "2001-12-31") 
test_eq([[ Calendar.ISO.Week(2003, 1)->format_ymd() ]], "2002-12-30") 
test_eq([[ Calendar.ISO.Week(2004, 1)->format_ymd() ]], "2003-12-29") 
test_eq([[ Calendar.ISO.Week(2005, 1)->format_ymd() ]], "2005-01-03") 
 
test_eq([[Calendar.Language["swe"]->week_day_name_from_number(1)]], "måndag") 
 
test_eq([[Calendar.ISO.Day (2007, 12, 31)->week()->month_day()]], 31); 
test_any([[ 
  object d = Calendar.ISO.Day (2007, 12, 01); 
  d->week_day(); 
  return d->range (d)->week()->year_no(); 
]], 2007) 
 
test_eq([[(Calendar.ISO.Week (2007, 52) + 1)->year_no()]], 2008) 
 
test_eq([[Calendar.ISO.Week (2007, 1)->distance (Calendar.ISO.Week (2008, 1))->number_of_weeks()]], 52) 
 
dnl Note: YMD.year and YMD.years are zero based, as opposed to the others. 
dnl It's uncertain whether that is due to design or mistake, but we'll have 
dnl to leave it at that anyway for compatibility. 
test_eq([[Calendar.ISO.Year(2007)->year()->year_no()]], 2007) 
test_eq([[Calendar.ISO.Year(2007)->year(0)->year_no()]], 2007) 
test_eq([[Calendar.ISO.Year(2007)->year(-1)->year_no()]], 2007) 
test_eq([[Calendar.ISO.Year(2007)->set_size(2)->year()->year_no()]], 2007) 
test_eq([[Calendar.ISO.Year(2007)->set_size(2)->year(0)->year_no()]], 2007) 
test_eq([[Calendar.ISO.Year(2007)->set_size(2)->year(1)->year_no()]], 2008) 
test_eq([[Calendar.ISO.Year(2007)->set_size(2)->year(-2)->year_no()]], 2007) 
test_eq([[Calendar.ISO.Year(2007)->set_size(2)->year(-1)->year_no()]], 2008) 
test_equal([[Calendar.ISO.Year(2007)->set_size(2)->years()->year_no()]], ({2007, 2008})) 
test_equal([[Calendar.ISO.Year(2007)->set_size(2)->years(0,0)->year_no()]], ({2007})) 
test_equal([[Calendar.ISO.Year(2007)->set_size(2)->years(1,1)->year_no()]], ({2008})) 
test_equal([[Calendar.ISO.Year(2007)->set_size(2)->years(0,1)->year_no()]], ({2007, 2008})) 
test_equal([[Calendar.ISO.Year(2007)->set_size(2)->years(-1,1)->year_no()]], ({2007, 2008})) 
test_equal([[Calendar.ISO.Year(2007)->set_size(2)->years(0,2)->year_no()]], ({2007, 2008})) 
 
test_eq([[Calendar.ISO.Month(2007,7)->month()->month_no()]], 7) 
test_eq([[Calendar.ISO.Month(2007,7)->month(1)->month_no()]], 7) 
test_eq([[Calendar.ISO.Month(2007,7)->month(-1)->month_no()]], 7) 
test_eq([[Calendar.ISO.Month(2007,7)->set_size(2)->month()->month_no()]], 7) 
test_eq([[Calendar.ISO.Month(2007,7)->set_size(2)->month(1)->month_no()]], 7) 
test_eq([[Calendar.ISO.Month(2007,7)->set_size(2)->month(2)->month_no()]], 8) 
test_eq([[Calendar.ISO.Month(2007,7)->set_size(2)->month(-2)->month_no()]], 7) 
test_eq([[Calendar.ISO.Month(2007,7)->set_size(2)->month(-1)->month_no()]], 8) 
test_equal([[Calendar.ISO.Month(2007,7)->set_size(2)->months()->month_no()]], ({7, 8})) 
test_equal([[Calendar.ISO.Month(2007,7)->set_size(2)->months(1,1)->month_no()]], ({7})) 
test_equal([[Calendar.ISO.Month(2007,7)->set_size(2)->months(2,2)->month_no()]], ({8})) 
test_equal([[Calendar.ISO.Month(2007,7)->set_size(2)->months(1,2)->month_no()]], ({7, 8})) 
test_equal([[Calendar.ISO.Month(2007,7)->set_size(2)->months(0,2)->month_no()]], ({7, 8})) 
test_equal([[Calendar.ISO.Month(2007,7)->set_size(2)->months(1,3)->month_no()]], ({7, 8})) 
 
test_eq([[Calendar.ISO.Week(2007,7)->week()->week_no()]], 7) 
test_eq([[Calendar.ISO.Week(2007,7)->week(1)->week_no()]], 7) 
test_eq([[Calendar.ISO.Week(2007,7)->week(-1)->week_no()]], 7) 
test_eq([[Calendar.ISO.Week(2007,7)->set_size(2)->week()->week_no()]], 7) 
test_eq([[Calendar.ISO.Week(2007,7)->set_size(2)->week(1)->week_no()]], 7) 
test_eq([[Calendar.ISO.Week(2007,7)->set_size(2)->week(2)->week_no()]], 8) 
test_eq([[Calendar.ISO.Week(2007,7)->set_size(2)->week(-2)->week_no()]], 7) 
test_eq([[Calendar.ISO.Week(2007,7)->set_size(2)->week(-1)->week_no()]], 8) 
test_equal([[Calendar.ISO.Week(2007,7)->set_size(2)->weeks()->week_no()]], ({7, 8})) 
test_equal([[Calendar.ISO.Week(2007,7)->set_size(2)->weeks(1,1)->week_no()]], ({7})) 
test_equal([[Calendar.ISO.Week(2007,7)->set_size(2)->weeks(2,2)->week_no()]], ({8})) 
test_equal([[Calendar.ISO.Week(2007,7)->set_size(2)->weeks(1,2)->week_no()]], ({7, 8})) 
test_equal([[Calendar.ISO.Week(2007,7)->set_size(2)->weeks(0,2)->week_no()]], ({7, 8})) 
test_equal([[Calendar.ISO.Week(2007,7)->set_size(2)->weeks(1,3)->week_no()]], ({7, 8})) 
 
test_eq([[Calendar.ISO.Day(2007,7,7)->day()->month_day()]], 7) 
test_eq([[Calendar.ISO.Day(2007,7,7)->day(1)->month_day()]], 7) 
test_eq([[Calendar.ISO.Day(2007,7,7)->day(-1)->month_day()]], 7) 
test_eq([[Calendar.ISO.Day(2007,7,7)->set_size(2)->day()->month_day()]], 7) 
test_eq([[Calendar.ISO.Day(2007,7,7)->set_size(2)->day(1)->month_day()]], 7) 
test_eq([[Calendar.ISO.Day(2007,7,7)->set_size(2)->day(2)->month_day()]], 8) 
test_eq([[Calendar.ISO.Day(2007,7,7)->set_size(2)->day(-2)->month_day()]], 7) 
test_eq([[Calendar.ISO.Day(2007,7,7)->set_size(2)->day(-1)->month_day()]], 8) 
test_equal([[Calendar.ISO.Day(2007,7,7)->set_size(2)->days()->month_day()]], ({7, 8})) 
test_equal([[Calendar.ISO.Day(2007,7,7)->set_size(2)->days(1,1)->month_day()]], ({7})) 
test_equal([[Calendar.ISO.Day(2007,7,7)->set_size(2)->days(2,2)->month_day()]], ({8})) 
test_equal([[Calendar.ISO.Day(2007,7,7)->set_size(2)->days(1,2)->month_day()]], ({7, 8})) 
test_equal([[Calendar.ISO.Day(2007,7,7)->set_size(2)->days(0,2)->month_day()]], ({7, 8})) 
test_equal([[Calendar.ISO.Day(2007,7,7)->set_size(2)->days(1,3)->month_day()]], ({7, 8})) 
 
test_eq([[Calendar.ISO.Week (2008, 1)->year_no()]], 2008) 
test_eq([[Calendar.ISO.Week (2008, 1)->year_day()]], 0) 
test_equal([[Calendar.ISO.Week ("julian", 2454466)->format_iso_week()]], "2008-W01") 
test_eq([[Calendar.ISO.Week (2008, 1)->set_size (Calendar.ISO.Day())->format_ymd()]], "2007-12-31") 
test_eq([[Calendar.ISO.Day (2007, 12, 31)->format_iso_week()]], "2008-W01") 
test_eq([[Calendar.ISO.Day (2007, 12, 31)->format_iso_week_short()]], "200801") 
 
dnl NOTE: The following tests just documents how the code behaves, NOT 
dnl how it should behave. Some of these are questionable, others are 
dnl clearly wrong. But trying to fix them is like opening a can of 
dnl worms and imho not possible to do without rethinking things a bit 
dnl and introducing some incompatibilities. That has been done in pike 
dnl >= 7.7. /mast 
test_eq([[Calendar.ISO.Day (2007, 12, 31)->set_size (Calendar.ISO.Week())->format_iso_week()]], "2007-W01") 
test_eq([[Calendar.ISO.Day (2007, 12, 31)->set_size (Calendar.ISO.Week())->year_no()]], 2007) 
test_eq([[Calendar.ISO.Week (2008, 1)->set_size (Calendar.ISO.Day())->year_no()]], 2008) 
test_equal([[ 
  Calendar.ISO.Week (2008, 1)->datetime() - (["timezone": 1, "unix": 1]) 
]], [[ 
  ([ 
    "day": 31, 
    "fraction": 0.0, 
    "hour": 0, 
    "julian": 2454466, 
    "minute": 0, 
    "month": 12, 
    "second": 0, 
    "week": 1, 
    "week_day": 1, 
    "year": 2008, 
    "yearday": -1 
  ]) 
]]) 
test_equal([[Calendar.ISO.Day (Calendar.ISO.Week(2008,1))->years()->year_no()]], ({2007, 2008})) 
test_equal([[Calendar.ISO.Month (Calendar.ISO.Week(2008,1))->years()->year_no()]], ({2007, 2008})) 
test_equal([[Calendar.ISO.Year (Calendar.ISO.Week(2008,1))->years()->year_no()]], ({2007})) 
test_equal([[Calendar.ISO.Week(2008,1)->years()->year_no()]], ({2008})) 
test_equal([[Calendar.ISO.Week(2008,1)->number_of_years()]], 1) 
test_eq([[Calendar.ISO.Year (Calendar.ISO.Week (2008, 1))->year_no()]], 2007) 
test_eq([[Calendar.ISO.Year (Calendar.ISO.Week (2008, 1))->number_of_years()]], 1) 
test_equal([[Calendar.ISO.Year (Calendar.ISO.Week (2008, 1))->years()->year_no()]], ({2007}))