-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpldate_test.sh
executable file
·325 lines (294 loc) · 9.24 KB
/
pldate_test.sh
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
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
#!/bin/sh
TestComplete () {
From="$1"
Expect="$2"
To="$(./pldate $From)"
if [ "$To" = "$Expect" ]; then
printf "%s => %s OK\n" "$From" "$To"
else
printf "%s => %s *** expected %s \n" "$From" "$To" "$Expect"
exit 9
fi
}
TestSet () {
From="$1"
Expect="$2"
To="$(./pldate set "$From")"
if [ "$To" = "$Expect" ]; then
printf "set %s => %s OK\n" "$From" "$To"
else
printf "set %s => %s *** expected %s \n" "$From" "$To" "$Expect"
exit 9
fi
}
TestAddDays () {
From="$1"
Add="$2"
Expect="$3"
To="$(./pldate set "$From" add-days "$Add")"
if [ "$To" = "$Expect" ]; then
printf "set %s add-days %s => %s OK\n" "$From" "$Add" "$To"
else
printf "set %s add-days %s => %s *** expected %s \n" "$From" "$Add" "$To" "$Expect"
exit 9
fi
}
TestSubDays () {
From="$1"
Sub="$2"
Expect="$3"
To="$(./pldate set "$From" sub-days "$Sub")"
if [ "$To" = "$Expect" ]; then
printf "set %s sub-days %s => %s OK\n" "$From" "$Sub" "$To"
else
printf "set %s sub-days %s => %s *** expected %s \n" "$From" "$Sub" "$To" "$Expect"
exit 9
fi
}
TestAddMonth () {
From="$1"
Add="$2"
Expect="$3"
To="$(./pldate set "$From" add-month "$Add")"
if [ "$To" = "$Expect" ]; then
printf "set %s add-month %s => %s OK\n" "$From" "$Add" "$To"
else
printf "set %s add-month %s => %s *** expected %s \n" "$From" "$Add" "$To" "$Expect"
exit 9
fi
}
TestSubMonth () {
From="$1"
Add="$2"
Expect="$3"
To="$(./pldate set "$From" sub-month "$Add")"
if [ "$To" = "$Expect" ]; then
printf "set %s sub-month %s => %s OK\n" "$From" "$Add" "$To"
else
printf "set %s sub-month %s => %s *** expected %s \n" "$From" "$Add" "$To" "$Expect"
exit 9
fi
}
TestAddYear () {
From="$1"
Add="$2"
Expect="$3"
To="$(./pldate set "$From" add-year "$Add")"
if [ "$To" = "$Expect" ]; then
printf "set %s add-year %s => %s OK\n" "$From" "$Add" "$To"
else
printf "set %s add-year %s => %s *** expected %s \n" "$From" "$Add" "$To" "$Expect"
exit 9
fi
}
TestSubYear () {
From="$1"
Sub="$2"
Expect="$3"
To="$(./pldate set "$From" sub-year "$Sub")"
if [ "$To" = "$Expect" ]; then
printf "set %s sub-year %s => %s OK\n" "$From" "$Sub" "$To"
else
printf "set %s sub-year %s => %s *** expected %s \n" "$From" "$Sub" "$To" "$Expect"
exit 9
fi
}
TestNextDow () {
From="$1"
Dow="$2"
Expect="$3"
To="$(./pldate set "$From" next-dow "$Dow")"
if [ "$To" = "$Expect" ]; then
printf "set %s next-dow %s => %s OK\n" "$From" "$Dow" "$To"
else
printf "set %s next-dow %s => %s *** expected %s \n" "$From" "$Dow" "$To" "$Expect"
exit 9
fi
}
TestPrevDow () {
From="$1"
Dow="$2"
Expect="$3"
To="$(./pldate set "$From" prev-dow "$Dow")"
if [ "$To" = "$Expect" ]; then
printf "set %s prev-dow %s => %s OK\n" "$From" "$Dow" "$To"
else
printf "set %s prev-dow %s => %s *** expected %s \n" "$From" "$Dow" "$To" "$Expect"
exit 9
fi
}
TestUpToDow () {
From="$1"
Dow="$2"
Expect="$3"
To="$(./pldate set "$From" upto-dow "$Dow")"
if [ "$To" = "$Expect" ]; then
printf "set %s upto-dow %s => %s OK\n" "$From" "$Dow" "$To"
else
printf "set %s upto-dow %s => %s *** expected %s \n" "$From" "$Dow" "$To" "$Expect"
exit 9
fi
}
TestDownToDow () {
From="$1"
Dow="$2"
Expect="$3"
To="$(./pldate set "$From" downto-dow "$Dow")"
if [ "$To" = "$Expect" ]; then
printf "set %s downto-dow %s => %s OK\n" "$From" "$Dow" "$To"
else
printf "set %s downto-dow %s => %s *** expected %s \n" "$From" "$Dow" "$To" "$Expect"
exit 9
fi
}
TestSetMday () {
From="$1"
Mday="$2"
Expect="$3"
To="$(./pldate set "$From" set-mday "$Mday")"
if [ "$To" = "$Expect" ]; then
printf "set %s set-mday %s => %s OK\n" "$From" "$Mday" "$To"
else
printf "set %s set-mday %s => %s *** expected %s \n" "$From" "$Mday" "$To" "$Expect"
exit 9
fi
}
TestSetYday () {
From="$1"
Yday="$2"
Expect="$3"
To="$(./pldate set "$From" set-yday "$Yday")"
if [ "$To" = "$Expect" ]; then
printf "set %s set-yday %s => %s OK\n" "$From" "$Yday" "$To"
else
printf "set %s set-yday %s => %s *** expected %s \n" "$From" "$Yday" "$To" "$Expect"
exit 9
fi
}
TestInternal () {
Ext="$1"
Int="$2"
Tmp1="$(./pldate set "$Ext" printf %I)"
Tmp2="$(./pldate set-int "$Int" print)"
if [ "$Tmp2" = "$Ext" -a "$Tmp1" = "$Int" ]; then
printf "ext=%s int=%s OK\n" "$Ext" "$Int"
else
printf "ext=%s int=%s tmp1=%s tmp2=%s **** Fail\n" "$Ext" "$Int" "$Tmp1" "$Tmp2"
exit 9
fi
}
TestSet 16010101 16010101
TestSet 18480315 18480315
TestSet 19680309 19680309
TestSet 21000228 21000228
TestAddDays 23001231 0 23001231
TestAddDays 16010301 -1 16010228
TestAddDays 16040301 -1 16040229
TestAddDays 17000301 -1 17000228
TestAddDays 20000301 -1 20000229
TestAddDays 23000301 -1 23000228
TestAddDays 19991231 +1 20000101
TestAddDays 19991231 +61 20000301
TestAddDays 20000301 -61 19991231
TestAddDays 20001231 +60 20010301
TestAddDays 20010301 -60 20001231
TestSubDays 20011212 0 20011212
TestSubDays 20011212 200 20010526
TestSubDays 20011212 -200 20020630
TestNextDow 20190420 0 20190421
TestNextDow 20190420 1 20190422
TestNextDow 20190420 2 20190423
TestNextDow 20190420 3 20190424
TestNextDow 20190420 4 20190425
TestNextDow 20190420 5 20190426
TestNextDow 20190420 6 20190427 # here 'next-dow' and 'upto-dow' differ
TestNextDow 20190420 7 20190421
TestPrevDow 20190420 0 20190414
TestPrevDow 20190420 1 20190415
TestPrevDow 20190420 2 20190416
TestPrevDow 20190420 3 20190417
TestPrevDow 20190420 4 20190418
TestPrevDow 20190420 5 20190419
TestPrevDow 20190420 6 20190413 # here 'prev-dow' and 'downto-dow' differ
TestPrevDow 20190420 7 20190414
TestUpToDow 20190420 0 20190421
TestUpToDow 20190420 1 20190422
TestUpToDow 20190420 2 20190423
TestUpToDow 20190420 3 20190424
TestUpToDow 20190420 4 20190425
TestUpToDow 20190420 5 20190426
TestUpToDow 20190420 6 20190420 # here 'next-dow' and 'upto-dow' differ
TestUpToDow 20190420 7 20190421
TestDownToDow 20190420 0 20190414
TestDownToDow 20190420 1 20190415
TestDownToDow 20190420 2 20190416
TestDownToDow 20190420 3 20190417
TestDownToDow 20190420 4 20190418
TestDownToDow 20190420 5 20190419
TestDownToDow 20190420 6 20190420 # here 'prev-dow' and 'downto-dow' differ
TestDownToDow 20190420 7 20190414
TestSetMday 23000201 -31 23000201
TestSetMday 23000201 -30 23000201
TestSetMday 23000201 -27 23000202
TestSetMday 23000201 -10 23000219
TestSetMday 23000201 -1 23000228
TestSetMday 23000201 0 23000201
TestSetMday 23000201 1 23000201
TestSetMday 23000201 30 23000228
TestSetMday 23000201 31 23000228
TestSetYday 17890315 -1 17891231
TestSetYday 17890315 0 17890101
TestSetYday 17890315 365 17891231
TestAddMonth 20010131 -100 19920930
TestAddMonth 20010131 -12 20000131
TestAddMonth 20010131 -11 20000229
TestAddMonth 20010131 -1 20001231
TestAddMonth 20010131 0 20010131
TestAddMonth 20010131 1 20010228
TestAddMonth 20010131 11 20011231
TestAddMonth 20010131 12 20020131
TestAddMonth 20010131 100 20090531
TestSubMonth 19920930 -100 20010130
TestSubMonth 20001231 -1 20010131
TestSubMonth 20010131 0 20010131
TestSubMonth 20010228 1 20010128
TestSubMonth 20090531 100 20010131
TestAddYear 20000229 +300 23000228
TestAddYear 20000229 +400 24000229
TestSubYear 24001231 799 16011231
TestSubYear 16011231 -799 24001231
TestInternal 16010101 000000
TestInternal 17001231 036523
TestInternal 17010101 036524
TestInternal 20001231 146096
TestInternal 20000229 145790
TestInternal 20000301 145791
TestInternal 24001231 292193
TestComplete 'set 19010101' 19010101
TestComplete 'set 19010101 add-days 365' 19020101
TestComplete 'set 19010101 add-days 365 next-dow 0' 19020105
TestComplete 'set 19010101 add-days 365 prev-dow 0' 19011229
TestComplete 'set 19450404 set-mday 1 sub-days 1' 19450331
TestComplete 'set 19450404 set-mday -1 add-days 1' 19450501
TestComplete 'set 20010531 set-month 12' '20011231'
TestComplete 'set 20010531 set-month 9' '20010930'
TestComplete 'set 20010531 set-month 1' '20010131'
TestComplete 'set 20010531 next-month 1' '20020131'
TestComplete 'set 20010531 next-month 5' '20020531'
TestComplete 'set 20010531 prev-month 1' '20010131'
TestComplete 'set 20010531 prev-month 1' '20010131'
TestComplete 'set 20010531 upto-month 5' '20010531'
TestComplete 'set 20010531 upto-month 4' '20020430'
TestComplete 'set 20010531 downto-month 5' '20010531'
TestComplete 'set 20010531 downto-month 6' '20000630'
TestComplete 'set 20010531 downto-month 12' '20001231'
TestComplete 'set 19681226
add-days 1
prev-dow 1
printf %Y%m%d-
next-dow 7 printf %Y%m%d' 19681223-19681229
TestComplete 'set 19681230
add-days 1
prev-dow 1
printf %Y%m%d.%w.%j-
next-dow 7 printf %Y%m%d.%w.%j' 19681230.1.365-19690105.0.005