summaryrefslogtreecommitdiffstats
path: root/libtdeedu/extdate/test_extdate.cpp
blob: d70d3e94259ace4e9ff8d42f5b87a79b743f26d0 (plain)
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
326
327
328
329
330
331
332
333
334
#include <stdlib.h>
#include <iostream>
#include "extdatetime.h"


void test1_unit(int a_year)
{
	std::cout << a_year << "  (TQDate|ExtDate): " << ((TQDate::leapYear(a_year)) ? "yes" : "no")
			<<"|"<< ((ExtDate::leapYear(a_year)) ? "yes" : "no") << std::endl;
}

void test1()
{
	int a_set_of_years[] =
	{
		1996,
		1997,
		1998,
		2000,
		1999,
		2001,
		1900,
		1800,
		1700,
		1600,
		2100,
		2200,
		2300,
		0,
		-1,
		-4,
		-100,
		-200,
		-300,
		-400,
		-500
	};
	uint i;
	std::cout << "Checking Leap Years:\n" << std::endl;
	for (i = 0 ; i < sizeof(a_set_of_years)/sizeof(a_set_of_years[0]) ; i++)
	{
		test1_unit(a_set_of_years[i]);
	}
	std::cout << "--------------------" << std::endl;
}

void test2_unit(int y, int m, int d)
{
	TQDate	q(y, m, d);
	ExtDate	e(y, m, d);
	int q_week_number = q.dayOfWeek();
	int e_week_number = e.dayOfWeek();
	int q_day_of_year = q.dayOfYear();
	int e_day_of_year = e.dayOfYear();
	std::cout << "(" << y << ", " << m << ", " << d << ") ::  "
			<< q.toString("dd.MMM.yyyy").local8Bit() << "  :  "
			<< q.dayOfWeek() << " : " << q_week_number << " : " << q_day_of_year << " :: "
			<< e.toString("%d.%b.%Y").local8Bit() << " : "
			<< e.dayOfWeek() << " : " << e_week_number << " : " << e_day_of_year << std::endl;
}

void test2()
{
	int a_set_of_dates[][3] =
	{
		{0, 1, 1},
		{1, 1, 1},
		{2, 1, 1},
		{3, 1, 1},
		{4, 1, 1},
		{5, 1, 1},
		{99, 1, 1},
		{100, 1, 1},
		{100, 12, 31},
		{101, 1, 1},
		{102, 1, 1},
		{103, 1, 1},
		{104, 1, 1},
		{399, 1, 1},
		{400, 1, 1},
		{401, 1, 1},
		{402, 1, 1},
		{403, 1, 1},
		{404, 1, 1},
		{2003, 1, 1},
		{2003, 1, 2},
		{2003, 1, 3},
		{2003, 1, 4},
		{2003, 1, 5},
		{2003, 1, 6},
		{2003, 1, 7},
		{2003, 1, 8},
		{2003, 1, 9},
		{2003, 1, 10},
		{2003, 1, 11},
		{2003, 1, 12},
		{2003, 1, 13},
		{2003, 1, 14},
		{2003, 1, 15},
		{2003, 1, 16},
		{2003, 1, 17},
		{2003, 1, 18},
		{2003, 12, 19},
		{2003, 12, 20},
		{2003, 12, 21},
		{2003, 12, 22},
		{2003, 12, 23},
		{2003, 12, 24},
		{2003, 12, 25},
		{2003, 12, 26},
		{2003, 12, 27},
		{2003, 12, 28},
		{2003, 12, 29},
		{2003, 12, 30},
		{2003, 12, 31},
		{2004, 1, 1},
		{2003, 11, 2}
	};
	uint i;
	std::cout << "(y, m, d) :: TQDate : Q.dayOfWeek() : Q.weekNumber() : Q.dayOfYear() :: ExtDate : E.dayOfWeek() : E.weekNumber() : E.dayOfYear()\n" << std::endl;

	for (i = 0 ; i < sizeof(a_set_of_dates)/sizeof(a_set_of_dates[0]) ; i++)
	{
		test2_unit(a_set_of_dates[i][0], a_set_of_dates[i][1], a_set_of_dates[i][2]);
	}
	std::cout << "--------------------" << std::endl;
}

void test3_unit(int y, int m, int d, int dm)
{
	TQDate	q(y, m, d);
	ExtDate	e(y, m, d);
	TQDate q2 = q.addMonths(dm);
	ExtDate e2 = e.addMonths(dm);
	std::cout << e.toString("%d.%b.%Y").local8Bit() << " + " << dm
		<< " months :: ExtDate : " << e2.toString("%d.%b.%Y").local8Bit()
		<< "   TQDate : " << q2.toString("dd.MMM.yyyy").local8Bit() << std::endl;
}

void test3()
{
	int a_set_of_dates_delta[][4] =
	{
		{2003, 11, 5, 0},
		{2003, 11, 5, 1},
		{2003, 11, 5, -1},
		{2003, 11, 5, 2},
		{2003, 11, 5, 3}
	};
	uint i;
	std::cout << "Adding Months:\n" << std::endl;
	for (i = 0 ; i < sizeof(a_set_of_dates_delta)/sizeof(a_set_of_dates_delta[0]) ; i++)
	{
		test3_unit(a_set_of_dates_delta[i][0], a_set_of_dates_delta[i][1], a_set_of_dates_delta[i][2], a_set_of_dates_delta[i][3]);
	}
	std::cout << "--------------------" << std::endl;
}
void test4_unit(int y, int m, int d, int dy)
{
	TQDate	q(y, m, d);
	ExtDate	e(y, m, d);
	TQDate	q2 = q.addYears(dy);
	ExtDate	e2 = e.addYears(dy);
	std::cout << e.toString("%d.%m.%Y").local8Bit() << " + " << dy << " years :: ExtDate : "
		<< e2.toString().local8Bit() << "   TQDate : "
		<< q2.toString().local8Bit() << std::endl;
}

void test4()
{
	int a_set_of_dates_delta[][4] =
	{
		{-1, 11, 5, 0},
		{-1, 11, 5, 1},
		{-1, 11, 5, 2},
		{2003, 11, 5, 1},
		{2003, 11, 5, -1},
		{2003, 11, 5, 2},
		{2003, 11, 5, 3}
	};
	uint i;
	std::cout << "Adding years:\n" << std::endl;
	for (i = 0 ; i < sizeof(a_set_of_dates_delta)/sizeof(a_set_of_dates_delta[0]) ; i++)
	{
		test4_unit(a_set_of_dates_delta[i][0], a_set_of_dates_delta[i][1], a_set_of_dates_delta[i][2], a_set_of_dates_delta[i][3]);
	}
	std::cout << "--------------------" << std::endl;
}

void test5_unit(int y, int m, int d, const char *qformat, const char *eformat)
{
	TQDate q(y, m, d);
	ExtDate e(y, m, d);

	if ( TQString(qformat) == "<default>" )
		std::cout << eformat << " : " << e.toString().local8Bit() << " :: "
				<< qformat << " : " << q.toString().local8Bit() << std::endl;
	else
		std::cout << eformat << " : " << e.toString(eformat).local8Bit() << " :: "
				<< qformat << " : " << q.toString(qformat).local8Bit() << std::endl;
}

void test5()
{
	const char *q_set_of_formats[7] =
	{
		"d.M.yy",
		"dd.MM.yy",
		"ddd.MMM.yy",
		"ddd dd.MMM.yy",
		"dddd.MMMM.yy",
		">dd.M.yyyy<",
		"<default>"
	};
	const char *e_set_of_formats[7] =
	{
		"%e.%n.%y",
		"%d.%m.%y",
		"%d.%b.%y",
		"%a %d.%b.%y",
		"%A.%B.%y",
		">%d.%n.%Y<",
		"<default>"
	};

	uint i;
	std::cout << "Date.toString(\"...\")" << std::endl;
	std::cout << "Ext Format : ExtDate :: Q Format : TQDate\n" << std::endl;

	for (i = 0 ; i < sizeof(q_set_of_formats)/sizeof(q_set_of_formats[0]) ; i++)
	{
		test5_unit(2003, 11, 5, q_set_of_formats[i], e_set_of_formats[i]);
	}
	std::cout << "--------------------" << std::endl;
}

void test6_unit(int y, int m, int d)
{
	std::cout << d << "/" << m << "/" << y << " :: "
		<< ( ExtDate::isValid(y, m, d) ? "TRUE" : "FALSE" ) << " : "
		<< ( TQDate::isValid(y, m, d) ? "TRUE" : "FALSE" ) << std::endl;
}

void test6()
{
	int a_set_of_dates[][3] =
	{
		{-1, 11, 5},
		{-1, 11, 5},
		{-1, 11, 5},
		{2003, 11, 5},
		{2003, -1, 5},
		{2003, 0, 5},
		{2003, 12, 5},
		{2003, 13, 5},
		{2003, 11, -2},
		{2003, 11, 0},
		{2003, 11, 40},
		{2004, 2, 28},
		{2004, 2, 29},
		{2004, 2, 30},
		{2003, 2, 28},
		{2003, 2, 29},
		{2003, 2, 30}
	};
	uint i;
	std::cout << "Date.isValid()" << std::endl;
	std::cout << "d/m/y :: ExtDate.isValid() : TQDate.isValid()\n" << std::endl;

	for (i = 0 ; i < sizeof(a_set_of_dates)/sizeof(a_set_of_dates[0]) ; i++)
	{
		test6_unit(a_set_of_dates[i][0], a_set_of_dates[i][1], a_set_of_dates[i][2]);
	}
	std::cout << "--------------------" << std::endl;
}

void test7()
{
	std::cout << "Express the current date:\n" << std::endl;
	TQDate q = TQDate::currentDate(TQt::LocalTime);
	ExtDate e = ExtDate::currentDate(TQt::TimeSpec(TQt::LocalTime));
	std::cout << "TQt::LocalTime :: ExtDate : " << e.toString().local8Bit() << "   TQDate : "
		<< q.toString().local8Bit() << std::endl;
	q = TQDate::currentDate(TQt::UTC);
	e = ExtDate::currentDate(TQt::UTC);
	std::cout << "TQt::UTC       :: ExtDate : " << e.toString().local8Bit() << "   TQDate : "
		<< q.toString().local8Bit() << std::endl;
	q = TQDate::currentDate();
	e = ExtDate::currentDate();
	std::cout << "<default>     :: ExtDate : " << e.toString().local8Bit() << "   TQDate : "
		<< q.toString().local8Bit() << std::endl;
	std::cout << "--------------------" << std::endl;
}

void test8() {
	std::cout << "Set dates using days 1-32 for Jan and Feb (some will be invalid): \n" << std::endl;
	std::cout << "    TQDate      :     ExtDate" << std::endl;

	for ( uint m=1; m<=2; ++m ) {
		for ( uint d=1; d<=32; ++d ) {

			TQDate   test1( 2004, m, d );
			ExtDate test2( 2004, m, d );
			std::cout << test1.toString( "ddd dd.MMM.yy" ).local8Bit() << "  :  "
		<< test2.toString( "%a %d.%b.%y" ).local8Bit() << std::endl;
		}
	}

	std::cout << "--------------------" << std::endl;
}

void test9() {
	std::cout << "TQDateTime : ExtDateTime: \n" << std::endl;
	TQDateTime q = TQDateTime::currentDateTime();
	ExtDateTime e = ExtDateTime::currentDateTime();

	std::cout << q.toString().local8Bit() << " : " << e.toString().local8Bit() << std::endl;
	std::cout << "--------------------" << std::endl;
}

int main(int argc, char *argv[])
{
	test1();
	test2();
	test3();
	test4();
	test5();
	test6();
	test7();
	test8();
	test9();
	exit(0);
}