TsDateTime.cpp
Go to the documentation of this file.
1 /* Copyright (C) 2008 National Institute For Space Research (INPE) - Brazil.
2 
3  This file is part of the TerraLib - a Framework for building GIS enabled applications.
4 
5  TerraLib is free software: you can redistribute it and/or modify
6  it under the terms of the GNU Lesser General Public License as published by
7  the Free Software Foundation, either version 3 of the License,
8  or (at your option) any later version.
9 
10  TerraLib is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU Lesser General Public License for more details.
14 
15  You should have received a copy of the GNU Lesser General Public License
16  along with TerraLib. See COPYING. If not, write to
17  TerraLib Team at <terralib-team@terralib.org>.
18  */
19 
20 // Unit-Test TerraLib
21 #include "TsDateTime.h"
22 
23 static te::dt::DateTime d(2010,8,9,15,58,39);
24 
26 
28 {
29 }
30 
32 {
33 }
34 
36 {
37 //#ifdef TE_COMPILE_ALL
39  //te::dt::DateTime d1;
40 
41 //#endif
42 }
43 
45 {
46 //#ifdef TE_COMPILE_ALL
47 
48  te::dt::DateTime d1(2010); //d1(2010,1,1,0,0,0)
49  CPPUNIT_ASSERT(d1.getYear() == 2010 && d1.getMonth() == 1 && d1.getDay() == 1 &&
50  d1.getHour() == 0 && d1.getMin() == 0 || d1.getSec() == 0);
51 
52  //Initial time...
53  te::dt::DateTime d2(1); //d2(1,1,1,0,0,0)
54  CPPUNIT_ASSERT(d2.getYear() == 1 && d2.getMonth() == 1 && d2.getDay() == 1 &&
55  d2.getHour() == 0 && d2.getMin() == 0 || d2.getSec() == 0);
56 
57  //It is accepting invalid year
58  te::dt::DateTime d3(0); //it will be d2(0,1,1,0,0,0)
59  CPPUNIT_ASSERT(d3.getTimeInSeconds() == 0);
60 
61 //#endif
62 }
63 
65 {
66 //#ifdef TE_COMPILE_ALL
67 
68  te::dt::DateTime d1(2010,12,31);
69  long long int d1_timeInSecs = d1.getTimeInSeconds();
70  te::dt::DateTime d1e; d1e.setTimeFromSeconds(d1_timeInSecs);
71  CPPUNIT_ASSERT(d1 == d1e);
72 
73  //It is accepting invalid date
74  te::dt::DateTime d2(2010,31,32);
75  long long int d2_timeInSecs = d2.getTimeInSeconds();
76  te::dt::DateTime d2e; d2e.setTimeFromSeconds(d2_timeInSecs);
77  CPPUNIT_ASSERT(d2.getMonth() <= 12 && d2.getDay() <= 31 );
78 
79 //#endif
80 }
82 {
83 //#ifdef TE_COMPILE_ALL
84 
85  te::dt::DateTime d1(2010,12,31,23,59,59);
86  long long int d1_timeInSecs = d1.getTimeInSeconds();
87  te::dt::DateTime d1e; d1e.setTimeFromSeconds(d1_timeInSecs);
88  CPPUNIT_ASSERT( d1.getYear() == d1e.getYear() || d1.getMonth() == d1e.getMonth() || d1.getDay() == d1e.getDay());
89  CPPUNIT_ASSERT( d1.getHour() == d1e.getHour() || d1.getMin() == d1e.getMin() || d1.getSec() == d1e.getSec());
90 
91 
92  //It is accepting invalid values for date and/or hour
93  te::dt::DateTime d2(2010,12,31,60,60,60);
94  long long int d2_timeInSecs = d2.getTimeInSeconds();
95  te::dt::DateTime d2e;
96  d2e.setTimeFromSeconds(d2_timeInSecs);
97  CPPUNIT_ASSERT_MESSAGE("Invalid date is being accepted", d2.getYear() == 2010 && d2.getMonth() == 12 && d2.getDay() == 31);
98  CPPUNIT_ASSERT_MESSAGE("Invalid hour is being accepted", d2.getHour() < 24 && d2.getMin() < 60 && d2.getSec() < 60);
99 
100 //#endif
101 }
102 
104 {
105 //#ifdef TE_COMPILE_ALL
106 
107  te::dt::DateTime d1(d);
108  CPPUNIT_ASSERT( d1.getYear() == d.getYear() && d1.getMonth() == d.getMonth() && d1.getDay() == d.getDay());
109  CPPUNIT_ASSERT( d1.getHour() == d.getHour() && d1.getMin() == d.getMin() && d1.getSec() == d.getSec());
110 
111 //#endif
112 }
113 
115 {
116 //#ifdef TE_COMPILE_ALL
117 
118  te::dt::DateTime d1 = d; //(2010,8,9,15,58,39)
119  te::dt::DateTime d2;
120  te::dt::DateTime d3;
121  d2.operator =(d);
122  d3 = d;
123 
124  CPPUNIT_ASSERT( d1.getYear() == d.getYear() && d1.getMonth() == d.getMonth() && d1.getDay() == d.getDay());
125  CPPUNIT_ASSERT( d1.getHour() == d.getHour() && d1.getMin() == d.getMin() && d1.getSec() == d.getSec());
126  CPPUNIT_ASSERT( d2.getYear() == d.getYear() && d2.getMonth() == d.getMonth() && d2.getDay() == d.getDay());
127  CPPUNIT_ASSERT( d2.getHour() == d.getHour() && d2.getMin() == d.getMin() && d2.getSec() == d.getSec());
128  CPPUNIT_ASSERT( d3.getYear() == d.getYear() && d3.getMonth() == d.getMonth() && d3.getDay() == d.getDay());
129  CPPUNIT_ASSERT( d3.getHour() == d.getHour() && d3.getMin() == d.getMin() && d3.getSec() == d.getSec());
130 
131 //#endif
132 }
133 
134 
136 {
137 //#ifdef TE_COMPILE_ALL
138  te::dt::DateTime d1(d); //(2010,8,9,15,58,39)
139  d1+= 20;
140  CPPUNIT_ASSERT(d1.getSec()== 59);
141 
142 //#endif
143 }
144 
146 {
147 //#ifdef TE_COMPILE_ALL
148  te::dt::DateTime d1(d); //2010,8,9,15,58,39
149  te::dt::DateTime d2,d3,d4;
150  long long int dif1,dif2,dif3;
151  //add 20 segundos
152  d2 = d1 + 20;
153  d3 = d1 + 2000;
154  d4 = d1 + 250666; //adding (2 dias, 21 horas, 37 min, 46 seg) = d4(2010,8,12,13,36,25)
155  dif1 = d2 - d1;
156  dif2 = d3.operator -(d1);
157  dif3 = d4 - d1;
158  CPPUNIT_ASSERT(dif1 == 20);
159  CPPUNIT_ASSERT(dif2 == 2000);
160  CPPUNIT_ASSERT(dif3 == 250666);
161  CPPUNIT_ASSERT(d4.getDay()==12);
162  CPPUNIT_ASSERT(d4.getHour()==13);
163  CPPUNIT_ASSERT(d4.getMin()==36);
164  CPPUNIT_ASSERT(d4.getSec()==25);
165 
166  CPPUNIT_ASSERT(d2 - 20 == d1);
167  CPPUNIT_ASSERT(d3 - 2000 == d1);
168  CPPUNIT_ASSERT(d4 - 250666 == d1);
169 
170 //#endif
171 }
172 
174 {
175 //#ifdef TE_COMPILE_ALL
176  te::dt::DateTime d1(d); //(2010,8,9,15,58,39)
177 
178  //subtracting segundos
179  d1-= 20;
180  CPPUNIT_ASSERT(d1.getSec()== 19);
181  d1-= 60;
182  CPPUNIT_ASSERT(d1.getSec()== 19 && d1.getMin()== 57); //(2010,8,9,15,57,19)
183  d1-= 121;
184  CPPUNIT_ASSERT(d1.getSec()== 18 && d1.getMin()== 55); //(2010,8,9,15,55,18)
185 
186 //#endif
187 }
188 
190 {
191 //#ifdef TE_COMPILE_ALL
192  te::dt::DateTime d1(d); //(2010,8,9,15,58,39)
193  te::dt::DateTime d2;
194  //subtract 20 segundos
195  d2 = d1 - 20;
196  CPPUNIT_ASSERT(d2.getSec()== 19);
197 
198 //#endif
199 }
200 
202 {
203 //#ifdef TE_COMPILE_ALL
204  te::dt::DateTime d1(d); //(2010,8,9,15,58,39)
205 
206  te::dt::DateTime d2(d1);
207  CPPUNIT_ASSERT(d1 == d2);
208 
209 //#endif
210 }
211 
213 {
214 //#ifdef TE_COMPILE_ALL
215  te::dt::DateTime d1(d); //(2010,8,9,15,58,39)
216  te::dt::DateTime d2 = d1 - 20;
217  CPPUNIT_ASSERT(d2.getSec() == 19);
218  CPPUNIT_ASSERT(d2 < d1);
219 
220 //#endif
221 }
222 
224 {
225 //#ifdef TE_COMPILE_ALL
226  te::dt::DateTime d1(d); //(2010,8,9,15,58,39)
227 
228  te::dt::DateTime d2 = d1 - 20;
229  te::dt::DateTime d3(d2);
230  CPPUNIT_ASSERT(d2 <= d1);
231  CPPUNIT_ASSERT(d3 <= d2);
232 
233 //#endif
234 }
235 
237 {
238 //#ifdef TE_COMPILE_ALL
239  te::dt::DateTime d1(d); //(2010,8,9,15,58,39)
240 
241  te::dt::DateTime d2 = d1 + 20;
242  te::dt::DateTime d3 = d1 - 20;
243 
244  long long int dif = d2 - d1;
245  CPPUNIT_ASSERT( dif == 20);
246  long long int dif1 = d1 - d2;
247  CPPUNIT_ASSERT( dif1 == -20);
248 
249 //#endif
250 }
251 
253 {
254 //#ifdef TE_COMPILE_ALL
255 
256  te::dt::DateTime d1(2010,8,9,15,58,39); //(2010,8,9,15,58,39)
257  te::dt::DateTime d2(2010,2,1,20,31,20);
258 
259 //#endif
260 }
261 
263 {
264 //#ifdef TE_COMPILE_ALL
265 
266  te::dt::DateTime d2(2010,8,9,15,58,39); //(2010,8,9,15,58,39)
267  te::dt::DateTime d1;
268  d1.setYear(2010);
269  d1.setMonth(8);
270  d1.setDay(9);
271  d1.setHour(15);
272  d1.setMin(58);
273  d1.setSec(39);
274 
275  int diasM= d1.getDaysFromMonth();
276  int diasM1 = te::dt::DateTime::getDaysFromMonth(d1.getYear(),d1.getMonth());
277  int diasY1 = d1.getDaysFromYear();
278  int diasY2 = te::dt::DateTime::getDaysFromYear(d1.getYear());
279 
280  CPPUNIT_ASSERT( d1 == d2);
281  CPPUNIT_ASSERT( d1.getDate() == d2.getDate());
282  CPPUNIT_ASSERT( d1.getYear() == d2.getYear());
283  CPPUNIT_ASSERT( d1.getMonth() == d2.getMonth());
284  CPPUNIT_ASSERT( d1.getDay() == d2.getDay());
285  CPPUNIT_ASSERT( d1.getTime() == d2.getTime());
286  CPPUNIT_ASSERT( d1.getHour() == d2.getHour());
287  CPPUNIT_ASSERT( d1.getMin() == d2.getMin());
288  CPPUNIT_ASSERT( d1.getSec() == d2.getSec());
289  CPPUNIT_ASSERT( d1.getDaysFromYear() == d2.getDaysFromYear());
290  CPPUNIT_ASSERT( d1.getMonthName() == d2.getMonthName());
291 
292  CPPUNIT_ASSERT( diasM == 31);
293  CPPUNIT_ASSERT( diasM1 == 31);
294  CPPUNIT_ASSERT( diasY1 == 365);
295  CPPUNIT_ASSERT( diasY2 == 365);
296  CPPUNIT_ASSERT (d1.getMonthName() == "august");
297  d1.setMonth("september");
298  CPPUNIT_ASSERT (d1.getMonthName() == "september");
299  CPPUNIT_ASSERT (d1.getMonth() == 9);
300 
301 //#endif
302 }
303 
305 {
306 //#ifdef TE_COMPILE_ALL
307 
308 //#endif
309 }
310 
312 {
313 //#ifdef TE_COMPILE_ALL
314 
315 //#endif
316 }
317 
319 {
320 //#ifdef TE_COMPILE_ALL
321  te::dt::DateTime d1;
322  d1.setDay(32);
323  CPPUNIT_ASSERT (d1.getDay() > 31 );
324 //#endif
325 }
326 
328 {
329 //#ifdef TE_COMPILE_ALL
330  te::dt::DateTime d1;
331  d1.setHour(25);
332  CPPUNIT_ASSERT (d1.getHour() > 23);
333 
334 
335 //#endif
336 }
337 
339 {
340 //#ifdef TE_COMPILE_ALL
341  te::dt::DateTime d1;
342  d1.setMin(60);
343  CPPUNIT_ASSERT (d1.getMin() > 59);
344 
345 //#endif
346 }
347 
349 {
350 //#ifdef TE_COMPILE_ALL
351  te::dt::DateTime d1;
352  d1.setSec(60);
353  CPPUNIT_ASSERT (d1.getSec() > 59);
354 
355 //#endif
356 }
357 
359 {
360 //#ifdef TE_COMPILE_ALL
361 
362 //#endif
363 }
364 
366 {
367 //#ifdef TE_COMPILE_ALL
368  te::dt::DateTime d1(d); //(2010,8,9,15,58,39)
369  te::dt::DateTime d2;
370  d2.setTimeFromSeconds(63416966319);
371  CPPUNIT_ASSERT( d1 == d2);
372 
373 //#endif
374 }
375 
377 {
378 //#ifdef TE_COMPILE_ALL
379 
380 //#endif
381 }
382 
384 {
385 //#ifdef TE_COMPILE_ALL
386 
387 //#endif
388 }
389 
391 {
392 //#ifdef TE_COMPILE_ALL
393 
394 //#endif
395 }
396 
398 {
399 //#ifdef TE_COMPILE_ALL
400 
401 //#endif
402 }
403 
405 {
406 //#ifdef TE_COMPILE_ALL
407 
408 //#endif
409 }
410 
412 {
413 //#ifdef TE_COMPILE_ALL
414 
415 //#endif
416 }
417 
419 {
420 //#ifdef TE_COMPILE_ALL
421 
422 //#endif
423 }
424 
426 {
427 //#ifdef TE_COMPILE_ALL
428 
429 //#endif
430 }
431 
433 {
434 //#ifdef TE_COMPILE_ALL
435  int dfyear = te::dt::DateTime::getNumberOfDays(1,1,31);
436  CPPUNIT_ASSERT( dfyear == 30); //shoud not be 31?
437 
438  dfyear = te::dt::DateTime::getNumberOfDays(1,2,1);
439  CPPUNIT_ASSERT( dfyear == 31); //shoud not be 32?
440 
441  dfyear = te::dt::DateTime::getNumberOfDays(1,2,28);
442  CPPUNIT_ASSERT( dfyear == 58);
443  dfyear = te::dt::DateTime::getNumberOfDays(1,12,31);
444  CPPUNIT_ASSERT( dfyear == 364);
445  dfyear = te::dt::DateTime::getNumberOfDays(2,12,31);
446  CPPUNIT_ASSERT( dfyear == 729);
447  dfyear = te::dt::DateTime::getNumberOfDays(2000,12,31);
448  CPPUNIT_ASSERT( dfyear == 730484);
449  dfyear = te::dt::DateTime::getNumberOfDays(3,12,31);
450  CPPUNIT_ASSERT( dfyear == 1094);
451  dfyear = te::dt::DateTime::getNumberOfDays(12,12,31);
452  CPPUNIT_ASSERT( dfyear == 4382);
453  dfyear = te::dt::DateTime::getNumberOfDays(2001,12,31);
454  CPPUNIT_ASSERT( dfyear == 730849);
455 
456 //#endif
457 }
458 
460 {
461 //#ifdef TE_COMPILE_ALL
462  int dyear = te::dt::DateTime::getDaysFromYear(2010);
463  CPPUNIT_ASSERT( dyear == 365);
464 
465  dyear = te::dt::DateTime::getDaysFromYear(2000);
466  CPPUNIT_ASSERT( dyear == 366);
467 
468 //#endif
469 }
470 
472 {
473 //#ifdef TE_COMPILE_ALL
474  te::dt::DateTime d1(d); //(2010,8,9,15,58,39)
475  int dfyear = d1.getDaysFromYear();
476  CPPUNIT_ASSERT( dfyear == 365);
477  te::dt::DateTime d2(2000,8,9);
478  dfyear = d2.getDaysFromYear();
479  CPPUNIT_ASSERT( dfyear == 366);
480  d2.setYear(3);
481  dfyear = d2.getDaysFromYear();
482  CPPUNIT_ASSERT( dfyear == 365);
483  d2.setYear(12);
484  dfyear = d2.getDaysFromYear();
485  CPPUNIT_ASSERT( dfyear == 366);
486 
487 
488 //#endif
489 }
490 
492 {
493 //#ifdef TE_COMPILE_ALL
494  te::dt::DateTime d1(d); //(2010,8,9,15,58,39)
495  int dfmonth = d1.getDaysFromMonth();
496  CPPUNIT_ASSERT( dfmonth == 31);
497  te::dt::DateTime d2(2000,2);
498  dfmonth = d2.getDaysFromMonth();
499  CPPUNIT_ASSERT( dfmonth == 29);
500  d2.setYear(2001);
501  dfmonth = d2.getDaysFromMonth();
502  CPPUNIT_ASSERT( dfmonth == 28);
503  d2.setYear(12);
504  dfmonth = d2.getDaysFromMonth();
505  CPPUNIT_ASSERT( dfmonth == 29);
506  d2.setMonth(6);
507  dfmonth = d2.getDaysFromMonth();
508  CPPUNIT_ASSERT( dfmonth == 30);
509 
510 //#endif
511 }
512 
514 {
515 //#ifdef TE_COMPILE_ALL
516 
517 //#endif
518 }
519 
521 {
522 //#ifdef TE_COMPILE_ALL
523  long long int d_timeInSecs = d.getTimeInSeconds();
524  te::dt::DateTime d1 = te::dt::DateTime::getDateTimeFromSeconds(10);
525  te::dt::DateTime d2 = te::dt::DateTime::getDateTimeFromSeconds(2*60*60);
526 
527  te::dt::DateTime d3 = te::dt::DateTime::getDateTimeFromSeconds(10*(24*60*60));
528  te::dt::DateTime d3x = te::dt::DateTime::getDateTimeFromSeconds(10*60*60 -1 ); //dia 9 e nao 10
529 
530  te::dt::DateTime d4 = te::dt::DateTime::getDateTimeFromSeconds(35*(24*60*60));
531  te::dt::DateTime d5 = te::dt::DateTime::getDateTimeFromSeconds(365*(24*60*60));
532  te::dt::DateTime d5x = te::dt::DateTime::getDateTimeFromSeconds(365*(24*60*60)-1);
533 
534  te::dt::DateTime d6 = te::dt::DateTime::getDateTimeFromSeconds(63416908800);
535  te::dt::DateTime d7 = te::dt::DateTime::getDateTimeFromSeconds(d_timeInSecs);
536 
537  te::dt::DateTime d1a(1,1,1,0,0,10);
538  te::dt::DateTime d2a(1,1,1,2,0,0);
539  te::dt::DateTime d3a(1,1,11,0,0,0);
540  te::dt::DateTime d3xa(1,1,1,9,59,59);
541 
542  te::dt::DateTime d4a(1,2,5,0,0,0);
543  te::dt::DateTime d5a(2,1,1,0,0,0);
544  te::dt::DateTime d5xa(1,12,31,23,59,59);
545 
546  te::dt::DateTime d6a(2010,8,9,0,0,0);
547 
548  te::dt::DateTime d7a(1,1,1,2,0,0);
549 
550 
551  CPPUNIT_ASSERT( d1 == d1a );
552  CPPUNIT_ASSERT( d2 == d2a );
553  CPPUNIT_ASSERT( d3 == d3a );
554  CPPUNIT_ASSERT( d3x == d3xa );
555  CPPUNIT_ASSERT( d4 == d4a );
556  CPPUNIT_ASSERT( d5 == d5 );
557  CPPUNIT_ASSERT( d5x == d5xa );
558  CPPUNIT_ASSERT( d6 == d6a );
559 
560  CPPUNIT_ASSERT( d7 == d );
561 
562  //#endif
563 }
564 
566 {
567 //#ifdef TE_COMPILE_ALL
568 
569  te::dt::DateTime d0(0,1,1); //should be invalid year = 0
570  te::dt::DateTime d1(1,1,1);
571  te::dt::DateTime d2(2,1,1);
572  te::dt::DateTime d3 = d2+100;
573  te::dt::DateTime d4 = d1+100;
574  te::dt::DateTime dd(2010,8,9,15,58,39); //(2010,8,9,15,58,39)
575  long long int d0_timeInSecs = d0.getTimeInSeconds();
576 
577  long long int d1_timeInSecs = d1.getTimeInSeconds();
578  long long int d2_timeInSecs = d2.getTimeInSeconds();
579  long long int d3_timeInSecs = d3.getTimeInSeconds();
580  long long int d4_timeInSecs = d4.getTimeInSeconds();
581  long long int dd_timeInSecs = dd.getTimeInSeconds();
582 
583  CPPUNIT_ASSERT( (d3_timeInSecs - d2_timeInSecs) == 100);
584  CPPUNIT_ASSERT( (d4_timeInSecs - d1_timeInSecs) == 100);
585  CPPUNIT_ASSERT( (dd_timeInSecs - d1_timeInSecs) == 63416966319);
586 
587 
588  //Invalid data
589  te::dt::DateTime d5(1,0,0);
590  long long int d5_timeInSecs = d5.getTimeInSeconds();
591  CPPUNIT_ASSERT_MESSAGE("Date invalid month=0, day=0", d5_timeInSecs < 0);
592 
593 //#endif
594 }
595 
597 {
598 //#ifdef TE_COMPILE_ALL
599  long long int timeInSecD = te::dt::DateTime::getTimeInSeconds(2010,8,9);
600  long long int timeInSecD1 = te::dt::DateTime::getTimeInSeconds(2010,8,10); //+24hs = 84600 sec
601  long long int timeInSec = te::dt::DateTime::getTimeInSeconds(2010,8,9,15,58,39);
602  long long int timeInSec1 = te::dt::DateTime::getTimeInSeconds(2010,8,9,15,58,59); //+20 sec
603  CPPUNIT_ASSERT(timeInSecD1 - timeInSecD == 86400);
604  CPPUNIT_ASSERT(timeInSecD == 63416908800);
605  CPPUNIT_ASSERT(timeInSec == 63416966319);
606  CPPUNIT_ASSERT(timeInSec1 - timeInSec == 20);
607 
608 //#endif
609 }
610 
612 {
613 //#ifdef TE_COMPILE_ALL
614  te::dt::DateTime dd(2010,8,9,15,58,39); //(2010,8,9,15,58,39)
615  long long int dd_timeInSecs = dd.getTimeInSeconds(dd);
616  CPPUNIT_ASSERT (dd_timeInSecs == 63416966319);
617 
618 //#endif
619 }
620 
622 {
623 //#ifdef TE_COMPILE_ALL
624  te::dt::DateTime dd(2010,8,9,15,58,39); //(2010,8,9,15,58,39)
626  long long int dif = d.getDiffInSeconds(dd);
627  long long int dif1 = dd.getDiffInSeconds(d);
628 
629  te::dt::DateTime df(2011,8,9,15,58,39); //(2010,8,9,15,58,39)
630  long long int diff = df.getDiffInSeconds(dd);
631  long long int ts1 = dd.getTimeInSeconds();
632  long long int ts2 = df.getTimeInSeconds();
633  long long int diff1 = ts2 - ts1 ; //should be equal diff
634  long long int diff_date = df - dd ; //should be equal diff
635 
636  CPPUNIT_ASSERT ( diff == diff1);
637  CPPUNIT_ASSERT ( diff_date == diff);
638 
639 
640 //#endif
641 }
642 
644 {
645 //#ifdef TE_COMPILE_ALL
646  te::dt::DateTime d1(2010,8,9 ,15,58,39);
647  te::dt::DateTime d2(2010,8,10,15,58,39);
649  long long int dif = te::dt::DateTime::getDiffInSeconds(d2,d1);
650  CPPUNIT_ASSERT ( dif == 86400); // 1 dia = 24*60*60 = 86400
651  d2+= 172800; //(+2 dias)
652  dif = te::dt::DateTime::getDiffInSeconds(d2,d1); // = 3 dias=259200sec
653  CPPUNIT_ASSERT ( dif == 259200);
654 
655 
656 //#endif
657 }
658 
660 {
661 //#ifdef TE_COMPILE_ALL
662  te::dt::DateTime d1(2010,8,9,15,58,39); //monday
663  te::dt::DateTime d2(2011,8,9,15,58,39); //tuesday
664  te::dt::DateTime d3(2010,2,31,15,58,39); //???invalid day
665 
666  int idx1, idx2, idx3;
667  idx1 = d1.getWeekDay();
668  idx2 = d2.getWeekDay();
669  idx3 = d3.getWeekDay();
670  CPPUNIT_ASSERT ( idx1 == 1 && idx2 == 2);
671 
672 //#endif
673 }
674 
676 {
677 //#ifdef TE_COMPILE_ALL
679 
680  te::dt::DateTime d1(2010,8,9,15,58,39);
681  te::dt::DateTime d2(2011,8,9,15,58,39);
682 
683  std::string weekName1 = d1.getWeekDayName();
684  std::string weekName2 = d2.getWeekDayName();
685  CPPUNIT_ASSERT ( weekName1 == "monday" && weekName2 == "tuesday");
686 
687 
688 //#endif
689 }
690 
692 {
693 //#ifdef TE_COMPILE_ALL
694  te::dt::DateTime d2(2010,8,9,5,5,5);
695  std::string dateF = d2.getDate();
696  std::string format_F1 = "2010-08-09" ;
697  CPPUNIT_ASSERT(dateF == format_F1);
698 
699  te::dt::DateTime d1(2010,8,9,15,58,39);
700  std::string dateF1 = d1.getDate();
701  std::string separator0 = "09/08/2010" ;
702  std::string separator1 = "09-08-2010" ;
703  std::string separator2 = "09.08.2010" ;
704 
705 //#endif
706 }
707 
709 {
710 //#ifdef TE_COMPILE_ALL
711  te::dt::DateTime d0(2010,8,9,15,58,39);
712  te::dt::DateTime d1(2010,8,9,15,58,39,-3,0);
713  te::dt::DateTime d2(2010,8,9,5,5,5,5,30);
714 
715  std::string dateF0 = d0.getDateTime();
716  std::string format_F0 = "2010-08-09 15:58:39Z" ;
717  CPPUNIT_ASSERT(dateF0 == format_F0);
718 
719  std::string dateF1 = d1.getDateTime();
720  std::string format_F1 = "2010-08-09 15:58:39-3:00" ;
721  CPPUNIT_ASSERT(dateF1 == format_F1);
722 
723  std::string dateF2 = d2.getDateTime(te::dt::DateTime::YYYY_MM);
724  std::string format_F2 = "2010-08 05:05:05+05:30" ;
725  CPPUNIT_ASSERT(dateF2 == format_F2);
726 
727  std::string dateF3 = d2.getDateTime(te::dt::DateTime::YYYYMMDD);
728  std::string format_F3 = "20100809 05:05:05+00:00" ;
729 
730  std::string dateF4 = d2.getDateTime(te::dt::DateTime::YYYY_MM_DD,te::dt::DateTime::SLASH,te::dt::DateTime::HH_MM_SS);
731  std::string format_F4 = "2010/08/09 05:05:05" ;
732  CPPUNIT_ASSERT(dateF4 == format_F4);
733 
734  std::string dateF5 = d2.getDateTime(te::dt::DateTime::YYYY_MM_DD,te::dt::DateTime::SLASH,te::dt::DateTime::HH_MM_SS_TZ,te::dt::DateTime::DOT);
735  std::string format_F5 = "2010/08/09 05.05.05+00.00" ;
736  CPPUNIT_ASSERT(dateF5 == format_F5);
737 
738 
739  std::string format0 = "09/08/2010 15:58:39" ;
740  std::string format1 = "09/august/2010 15:58:39" ;
741  std::string format2 = "08/09/2010 15:58:39" ;
742  std::string format3 = "august/09/2010 15:58:39" ;
743  std::string format4 = "2010/august/09 15:58:39" ;
744  std::string format5 = "2010/august/09 15:58:39" ;
745  std::string format6 = "monday 09/2010 15:58:39" ;
746  std::string format7 = "monday 09/august/2010 15:58:39" ;
747  std::string format8 = "monday 09/2010 15:58:39" ;
748  std::string format9 = "monday august/09/2010 15:58:39" ;
749  std::string format10 ="monday 2010/08/09 15:58:39" ;
750  std::string format11 = "monday 2010/august/09 15:58:39" ;
751 
752 //#endif
753 }
754 
756 {
757 //#ifdef TE_COMPILE_ALL
758 
759  te::dt::DateTime d2(2010,8,9,5,5,5);
760 
761  std::string tt = d2.getTime();
762  std::string format_t1 = "05:05:05Z" ;
763  CPPUNIT_ASSERT(tt == format_t1);
764 
765 //#endif
766 }
CPPUNIT_TEST_SUITE_REGISTRATION(TsDateTime)
void tcDateTime()
Test Case: It creates a date time with local date. The date and time are obtained from the system clo...
Definition: TsDateTime.cpp:35
void tcGetDaysFromYear1()
Definition: TsDateTime.cpp:459
Test suite for the DateTime class.
Test suite for the DateTime Class.
Definition: TsDateTime.h:60
void tcGetUTC()
Definition: TsDateTime.cpp:425
void tcDateTimeSubDeltaSecs()
Test Case: Subtract &#39;delta&#39; seconds and assign to this current date.
Definition: TsDateTime.cpp:173
void tcDateTimeAddDeltaSecs1()
Test Case: Add &#39;delta&#39; seconds and return date.
Definition: TsDateTime.cpp:145
void tcSetTimeFromSeconds()
Definition: TsDateTime.cpp:365
void tcDateTimeAssign()
Test Case: Assignment operator.
Definition: TsDateTime.cpp:114
void tcGetHour()
Definition: TsDateTime.cpp:404
void tcDateTimeEqualOp()
Test Case: Operator ==.
Definition: TsDateTime.cpp:201
void tcSetDay()
Definition: TsDateTime.cpp:318
void tcSetMonth()
Definition: TsDateTime.cpp:311
void tcDateTimeParamsDateHour()
Test Case: It creates a custom date time with a given params ymdhms.
Definition: TsDateTime.cpp:81
void tcGetMonthName()
Definition: TsDateTime.cpp:390
void tcSetUTC()
Definition: TsDateTime.cpp:358
void tcSetYear()
Test Case:It initializes the date time with Y , M, D, H, Min, Sec, UTC, TimeFromSecs.
Definition: TsDateTime.cpp:304
void tcSetHour()
Definition: TsDateTime.cpp:327
void tcGetMonth()
Definition: TsDateTime.cpp:383
void tcGetDateTimeFromSeconds()
Definition: TsDateTime.cpp:520
void tearDown()
Definition: TsDateTime.cpp:31
void tcGetYear()
Definition: TsDateTime.cpp:376
void tcGetDiffInSeconds1()
Definition: TsDateTime.cpp:643
static te::dt::DateTime d(2010, 8, 9, 15, 58, 39)
void tcGetTime()
Definition: TsDateTime.cpp:755
void tcGetDaysFromYear()
Definition: TsDateTime.cpp:471
void tcDateTimeMinorEqOp()
Test Case: Operator <=.
Definition: TsDateTime.cpp:223
void tcDateTimeMinorOp()
Test Case: Operator <.
Definition: TsDateTime.cpp:212
void tcGetDate()
Definition: TsDateTime.cpp:691
void tcDateTimeConstructor()
Test Case: Copy constructor.
Definition: TsDateTime.cpp:103
void tcDateTimeParamsY()
Test Case: It creates a custom date time with a given params ymdhms.
Definition: TsDateTime.cpp:44
void tcDateTimeSubDeltaSecs1()
Test Case: Subtract &#39;delta&#39; seconds and return date.
Definition: TsDateTime.cpp:189
void tcGetNumberOfDays()
Definition: TsDateTime.cpp:432
void tcSetSec()
Definition: TsDateTime.cpp:348
void tcDateTimeAddDeltaSecs()
Test Case: Add &#39;delta&#39; seconds and assign to this current date.
Definition: TsDateTime.cpp:135
void tcGetTimeInSecondsDT()
Definition: TsDateTime.cpp:611
void tcGetSec()
Definition: TsDateTime.cpp:418
void tcGetDateTime()
Definition: TsDateTime.cpp:708
void tcDateTimeDifference()
Test Case: it returns the difference between the times in seconds.
Definition: TsDateTime.cpp:236
void tcGetTimeInSeconds()
Definition: TsDateTime.cpp:565
void tcDateTimeParamsDate()
Test Case: It creates a custom date time with a given params ymdhms.
Definition: TsDateTime.cpp:64
void tcSetMin()
Definition: TsDateTime.cpp:338
void tcSetDate()
Test Case:It initializes the date time.
Definition: TsDateTime.cpp:252
void tcGetTimeInSecondsD()
Definition: TsDateTime.cpp:596
void tcGetWeekName()
Definition: TsDateTime.cpp:675
void tcSetAll()
Test Case:It get Y, M, D, H, Min, Sec, UTC, etc.
Definition: TsDateTime.cpp:262
void tcGetWeek()
Definition: TsDateTime.cpp:659
void tcGetMin()
Definition: TsDateTime.cpp:411
void tcGetDaysFromMonth()
Definition: TsDateTime.cpp:491
void tcGetDay()
Definition: TsDateTime.cpp:397
void setUp()
Definition: TsDateTime.cpp:27
void tcGetNow()
Definition: TsDateTime.cpp:513
void tcGetDiffInSeconds()
Definition: TsDateTime.cpp:621