DCL 4.0
Loading...
Searching...
No Matches
DateTime.cpp
Go to the documentation of this file.
1#include <dcl/Config.h>
2
3#if __DCL_WINDOWS
4 #include <windows.h> // GetSystemTime
5 #include <sys/timeb.h> // _ftime_s
6 #include <time.h> // _get_timezone
7#else
8 #include <sys/time.h> // gettimeofday
9 #include <time.h> // localtime_r
10#endif
11
12#include <string.h> // memset
13#include <wchar.h> // wcsftime
14
15#include <dcl/DateTime.h>
16
17#if __DCL_HAVE_ALLOC_DEBUG
18#undef __DCL_ALLOC_LEVEL
19#define __DCL_ALLOC_LEVEL __DCL_ALLOC_INTERNAL
20#endif
21
22#if __DCL_DEBUG
23#undef __THIS_FILE__
24static const char_t __THIS_FILE__[] = __T("dcl/DateTime.cpp");
25#endif
26
27__DCL_BEGIN_NAMESPACE
28
30{
31 m_nJDay = 0;
32}
33
34Date::Date(const Date& src)
35{
36 m_nJDay = src.m_nJDay;
37}
38
39Date::Date(int nYear, int nMonth, int nDay)
40{
41 assign(nYear, nMonth, nDay);
42}
43
44Date::Date(long nDays)
45{
46 assign(nDays);
47}
48
49void Date::assign(int nYear, int nMonth, int nDay)
50{
51 __DCL_ASSERT(Date::isValid(nYear, nMonth, nDay));
52
54 nYear,
55 nMonth,
56 nDay
57 );
58}
59
60#define AD_START 220866926 // 0001-01-01
61#define BC_END (AD_START - 367) // -0001-01-31
62
63void Date::assign(long nDays)
64{
65 if (nDays < 0)
66 m_nJDay = nDays + BC_END + 1;
67 else if (nDays > 0)
68 m_nJDay = nDays + AD_START - 1;
69 else
70 // set NULL date
71 m_nJDay = nDays;
72}
73
74long Date::days() const
75{
76 if (m_nJDay <= BC_END)
77 return m_nJDay - BC_END - 1;
78 else if (m_nJDay >= AD_START)
79 return m_nJDay - AD_START + 1;
80 else {
82 return m_nJDay;
83 }
84}
85
87{
89
90 if (m_nJDay == BC_END)
92 else
93 m_nJDay++;
94
95 return *this;
96}
97
99{
100 __DCL_ASSERT(m_nJDay != 0);
101
102 Date dSave = m_nJDay;
103
104 if (m_nJDay == BC_END)
106 else
107 m_nJDay++;
108
109 return dSave;
110}
111
113{
114 __DCL_ASSERT(m_nJDay != 0);
115
116 if (m_nJDay == AD_START)
117 m_nJDay = BC_END;
118 else
119 m_nJDay--;
120
121 return *this;
122}
123
125{
126 __DCL_ASSERT(m_nJDay != 0);
127
128 Date dSave = m_nJDay;
129
130 if (m_nJDay == AD_START)
131 m_nJDay = BC_END;
132 else
133 m_nJDay--;
134
135 return dSave;
136}
137
138const Date& Date::operator = (const Date& src)
139{
140 m_nJDay = src.m_nJDay;
141 return *this;
142}
143
144const Date& Date::operator += (long nDays)
145{
146 __DCL_ASSERT(m_nJDay != 0);
147
148 if (m_nJDay <= BC_END) {
149 m_nJDay += nDays - BC_END;
150
151 if (m_nJDay <= 0)
152 m_nJDay += BC_END;
153 else
154 m_nJDay += AD_START - 1;
155 }
156 else {
158
159 m_nJDay += nDays - AD_START;
160
161 if (m_nJDay >= 0)
162 m_nJDay += AD_START;
163 else
164 m_nJDay += BC_END + 1;
165 }
166
167
168 return *this;
169}
170
171const Date& Date::operator -= (long nDays)
172{
173 __DCL_ASSERT(m_nJDay != 0);
174
175 return operator += (-nDays);
176}
177
178DCLCAPI Date operator + (const Date& d, long nDays)
179{
180 Date result = d;
181 result += nDays;
182 return result;
183}
184
185void Date::decode(int& nYear, int& nMonth, int& nDay) const
186{
187 convertJulianToGregorian(m_nJDay, nYear, nMonth, nDay);
188}
189
190int Date::year() const
191{
192 int nYear, nMonth, nDay;
193 convertJulianToGregorian(m_nJDay, nYear, nMonth, nDay);
194 return nYear;
195}
196
197int Date::month() const
198{
199 int nYear, nMonth, nDay;
200 convertJulianToGregorian(m_nJDay, nYear, nMonth, nDay);
201 return nMonth;
202}
203
204int Date::day() const
205{
206 int nYear, nMonth, nDay;
207 convertJulianToGregorian(m_nJDay, nYear, nMonth, nDay);
208 return nDay;
209}
210
212{
213 return (((m_nJDay + 1) % 7) + 7) % 7 + 1;
214}
215
217{
218 return m_nJDay - convertGregorianToJulian(year(), 1, 1) + 1;
219}
220
221static const int monthDays[] =
222{
223// 1 2 3 4 5 6 7 8 9 10 11 12
224 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31
225};
226
228{
229 int nYear, nMonth, nDay;
230 convertJulianToGregorian(m_nJDay, nYear, nMonth, nDay);
231 if (nMonth == 2 && isLeapYear(nYear))
232 return 29;
233
234 return monthDays[nMonth];
235}
236
238{
239 int nYear, nMonth, nDay;
240 convertJulianToGregorian(m_nJDay, nYear, nMonth, nDay);
241
242 if (isLeapYear(nYear))
243 return 366;
244 return 365;
245}
246
247String Date::toString() const
248{
249 int nYear, nMonth, nDay;
250 decode(nYear, nMonth, nDay);
251 return String::format(L"%04d-%02d-%02d", nYear, nMonth, nDay);
252}
253
254const wchar_t* Date::FORMAT_STRING = L"%Y-%m-%d";
255
256String Date::toStringF(const wchar_t* pszFormat) const
257{
258 if (!pszFormat)
259 pszFormat = FORMAT_STRING;
260
261 __DCL_ASSERT(*pszFormat != L'\0');
262
263 int nYear, nMonth, nDay;
264 decode(nYear, nMonth, nDay);
265
266 struct tm t;
267 memset(&t, 0, sizeof(struct tm));
268 t.tm_year = nYear - 1900;
269 t.tm_mon = nMonth - 1;
270 t.tm_mday = nDay;
271 t.tm_isdst = -1;
272
273 CharBuffer* buf = CharBuffer::create(DATETIME_FORMAT_BUFFER_SIZE);
274 size_t n = wcsftime(buf->data(), DATETIME_FORMAT_BUFFER_SIZE, pszFormat, &t);
275 __DCL_ASSERT(buf->__allocLength >= n);
276 buf->__dataLength = n;
277
278 String r = buf;
279 buf->release();
280 return r;
281}
282
283// 알고리즘 출처
284// Communications of the ACM, Vol 6, No 8.
286 int y, int m, int d
287 )
288{
289 if (y == 0) {
290 __DCL_ASSERT(m == 0 && d == 0);
291 return 0;
292 }
293
294 y += 600000;
295
296 int c, ya;
297 if (m > 2)
298 m -= 3;
299 else {
300 m += 9;
301 y--;
302 }
303 c = y / 100;
304 ya = y - 100 * c;
305
306 return (146097 * c) / 4
307 + (1461 * ya) / 4
308 + (153 * m + 2) / 5
309 + d
310 + 1721119;
311}
312
314 long j,
315 int& y, int& m, int& d
316 )
317{
318 if (j == 0) {
319 y = 0;
320 m = 0;
321 d = 0;
322 }
323 else {
324 j -= 1721119;
325
326 y = (4 * j - 1) / 146097;
327 j = 4 * j - 1 - 146097 * y;
328 d = j / 4;
329
330 j = (4 * d + 3) / 1461;
331 d = 4 * d + 3 - 1461 * j;
332 d = (d + 4) / 4;
333
334 m = (5 * d - 3) / 153;
335 d = 5 * d - 3 - 153 * m;
336 d = (d + 5 ) / 5;
337
338 y = 100 * y + j;
339 if (m < 10)
340 m += 3;
341 else {
342 m -= 9;
343 y++;
344 }
345
346 y -= 600000;
347 }
348}
349
350bool Date::isValid(int y, int m, int d)
351{
352 if (y == 0) {
353 // null date
354 if (m == 0 && d == 0)
355 return true;
356 }
357 else {
358 if ((-9999 <= y && y <= 9999) &&
359 (0 < m && m <= 12)
360 && (0 < d)) {
361 if (m == 2 && d == 29)
362 return Date::isLeapYear(y);
363 else
364 return d <= monthDays[m];
365 }
366 }
367 return false;
368}
369
371{
372 return (y % 4 == 0 && y % 100 != 0) || y % 400 == 0;
373}
374
375
377
379{
380 m_uMilliSeconds = 0;
381}
382
383
384Time::Time(const Time& src)
385{
387}
388
389#define SEC_PER_DAY 86400
390#define MSEC_PER_DAY 86400000
391#define SEC_PER_HOUR 3600
392#define MSEC_PER_HOUR 3600000
393#define SEC_PER_MIN 60
394#define MSEC_PER_MIN 60000
395
396Time::Time(int nHour, int nMin, int nSec, int nMSec /* = 0 */)
397{
398 assign(nHour, nMin, nSec, nMSec);
399}
400
401Time::Time(long nTotalMSecs)
402{
403 assign(nTotalMSecs);
404}
405
406void Time::assign(int nHour, int nMin, int nSec, int nMSec /* = 0 */)
407{
408 long ms = nHour * MSEC_PER_HOUR
409 + nMin * MSEC_PER_MIN
410 + nSec * 1000
411 + nMSec;
412
413 ms %= MSEC_PER_DAY;
414 ms += MSEC_PER_DAY;
416}
417
418void Time::assign(long nTotalMSecs)
419{
420 nTotalMSecs %= MSEC_PER_DAY;
421 nTotalMSecs += MSEC_PER_DAY;
422 m_uMilliSeconds = nTotalMSecs % MSEC_PER_DAY;
423}
424
425
426const Time& Time::operator = (const Time& src)
427{
429 return *this;
430}
431
432const Time& Time::operator += (long nMilliSeconds)
433{
434 long ms = m_uMilliSeconds + nMilliSeconds;
435 ms %= MSEC_PER_DAY;
436 ms += MSEC_PER_DAY;
438
439 return *this;
440}
441
442const Time& Time::operator -= (long nMilliSeconds)
443{
444 long ms = m_uMilliSeconds - nMilliSeconds;
445 ms %= MSEC_PER_DAY;
446 ms += MSEC_PER_DAY;
448
449 return *this;
450}
451
452DCLCAPI Time operator + (const Time& t, long nMilliSeconds)
453{
454 Time result = t;
455 result += nMilliSeconds;
456 return result;
457}
458
459void Time::decode(int& nHour, int& nMin, int& nSec, int& nMSec) const
460{
463 nSec = (m_uMilliSeconds % MSEC_PER_MIN) / 1000;
464 nMSec = m_uMilliSeconds % 1000;
465}
466
467int Time::hour() const // 0 ~ 23
468{
470}
471
472int Time::minute() const // 0 ~ 59
473{
475}
476
477int Time::second() const // 0 ~ 59
478{
479 return (m_uMilliSeconds % MSEC_PER_MIN) / 1000;
480}
481
482int Time::msecond() const // 0 ~ 999
483{
484 return m_uMilliSeconds % 1000;
485}
486
487// HH:MM:SS.MS
488String Time::toString() const
489{
490 return String::format(L"%02d:%02d:%02d.%03d",
491 hour(),
492 minute(),
493 second(),
494 msecond()
495 );
496}
497
498const wchar_t* Time::FORMAT_STRING = L"%H:%M:%S";
499
500String Time::toStringF(const wchar_t* pszFormat)
501{
502 if (!pszFormat)
503 pszFormat = FORMAT_STRING;
504
505 __DCL_ASSERT(*pszFormat != L'\0');
506
507 struct tm t;
508 memset(&t, 0, sizeof(struct tm));
509 t.tm_hour = hour();
510 t.tm_min = minute();
511 t.tm_sec = second();
512 t.tm_isdst = -1;
513
514 CharBuffer* buf = CharBuffer::create(DATETIME_FORMAT_BUFFER_SIZE);
515 size_t n = wcsftime(buf->data(), DATETIME_FORMAT_BUFFER_SIZE, pszFormat, &t);
516 __DCL_ASSERT(buf->__allocLength <= n);
517 buf->__dataLength = n;
518
519 String r = buf;
520 buf->release();
521 return r;
522}
523
524// static members
525bool Time::isValid(int nHour, int nMin, int nSec, int nMSec)
526{
527 return (0 <= nHour && nHour <= 23)
528 && (0 <= nMin && nMin <= 59)
529 && (0 <= nSec && nSec <= 59)
530 && (0 <= nMSec && nMSec <= 999);
531}
532
533
535
540
545
546Interval::Interval(int nDays, int nMilliSeconds)
547{
548 assign(nDays, nMilliSeconds);
549}
550
552 int nHours, int nMinutes, int nSeconds,
553 int nMilliSeconds
554 )
555{
556 assign(nDays, nHours, nMinutes, nSeconds, nMilliSeconds);
557}
558
559Interval::Interval(int64_t nTotalMilliSeconds)
560{
561 assign(nTotalMilliSeconds);
562}
563
564void Interval::assign(int nDays, int nMilliSeconds)
565{
566 m_nMilliSeconds = (int64_t)nDays * MSEC_PER_DAY + nMilliSeconds;
567}
568
569void Interval::assign(int nDays,
570 int nHours, int nMinutes, int nSeconds,
571 int nMilliSeconds
572 )
573{
574 m_nMilliSeconds= (int64_t)nDays * MSEC_PER_DAY
575 + (int64_t)nHours * MSEC_PER_HOUR
576 + (int64_t)nMinutes * MSEC_PER_MIN
577 + nSeconds * 1000
578 + nMilliSeconds;
579}
580
581void Interval::assign(int64_t nTotalMilliSeconds)
582{
583 m_nMilliSeconds = nTotalMilliSeconds;
584}
585
587{
589
590 return *this;
591}
592
594{
596
597 return *this;
598}
599
601{
603
604 return *this;
605}
606
608{
610 return iv;
611}
612
614{
616 return iv;
617}
618
619void Interval::decode(long& nDays,
620 int& nHours, int& nMinutes, int& nSeconds,
621 int& nMilliSeconds
622 ) const
623{
624 nDays = (long)(m_nMilliSeconds / MSEC_PER_DAY);
625 nHours = (int)((m_nMilliSeconds % MSEC_PER_DAY) / MSEC_PER_HOUR);
626 nMinutes = (int)((m_nMilliSeconds % MSEC_PER_HOUR) / MSEC_PER_MIN);
627 nSeconds = (int)((m_nMilliSeconds % MSEC_PER_MIN) / 1000);
628 nMilliSeconds = (int)(m_nMilliSeconds % 1000);
629}
630
631void Interval::decode(long& nDays, long& nMilliSeconds)
632{
633 nDays = (long)(m_nMilliSeconds / MSEC_PER_DAY);
634 nMilliSeconds = (long)(m_nMilliSeconds % MSEC_PER_DAY);
635}
636
637long Interval::days() const
638{
639 return (long)(m_nMilliSeconds / MSEC_PER_DAY);
640}
641
642int Interval::hour() const
643{
644 return (int)((m_nMilliSeconds % MSEC_PER_DAY) / MSEC_PER_HOUR);
645}
646
648{
649 return (int)((m_nMilliSeconds % MSEC_PER_HOUR) / MSEC_PER_MIN);
650}
651
653{
654 return (int)((m_nMilliSeconds % MSEC_PER_MIN) / 1000);
655}
656
658{
659 return (int)(m_nMilliSeconds % 1000);
660}
661
662int64_t Interval::totalHours() const
663{
665}
666
668{
670}
671
673{
674 return m_nMilliSeconds / 1000;
675}
676
677String Interval::toString() const
678{
679 long d;
680 int h, m, s, ms;
681 decode(d, h, m, s, ms);
682 if (m_nMilliSeconds < 0) {
683 return String::format(L"-%ld %02d:%02d:%02d.%03d",
684 -d,
685 -h, -m, -s, -ms
686 );
687 }
688 else {
689 return String::format(L"+%ld %02d:%02d:%02d.%03d",
690 d,
691 h, m, s, ms
692 );
693 }
694}
695
696// static members
697
700{
701 m_date = src.m_date;
702 m_time = src.m_time;
703}
704
706{
707 assign(time);
708}
709
711{
712 m_date = date;
713 m_time = time;
714}
715
716DateTime::DateTime(int nYear, int nMonth, int nDay,
717 int nHour, int nMin, int nSec, int nMSec /* = 0 */)
718{
719 m_date.assign(nYear, nMonth, nDay);
720 m_time.assign(nHour, nMin, nSec, nMSec);
721}
722
723void DateTime::assign(time_t timer)
724{
725 long tm_gmtoff = 0;
726
727#if __DCL_WINDOWS
728 long seconds;
729 _get_timezone(&seconds);
730 tm_gmtoff = -seconds;
731#else
732 struct tm tm;
733 localtime_r(&timer, &tm);
734 tm_gmtoff = tm.tm_gmtoff;
735#endif
736
737 m_date.assign(
738 (long) (719163 + ((timer + tm_gmtoff) / SEC_PER_DAY)) // 1970-01-01 00:00:00 + time
739 );
740 m_time.assign(
741 0,
742 0,
743 timer % SEC_PER_DAY + tm_gmtoff,
744 0
745 );
746}
747
748void DateTime::assign(const Date& date, const Time& time)
749{
750 m_date = date;
751 m_time = time;
752}
753
754void DateTime::assign(int nYear, int nMonth, int nDay,
755 int nHour, int nMin, int nSec, int nMSec /* = 0 */)
756{
757 m_date.assign(nYear, nMonth, nDay);
758 m_time.assign(nHour, nMin, nSec, nMSec);
759}
760
762{
763 m_date = src.m_date;
764 m_time = src.m_time;
765
766 return *this;
767}
768
770{
771 int64_t ms = (int64_t)m_date.days() * MSEC_PER_DAY
772 + (int64_t)m_time.totalMilliSeconds()
773 + iv.totalMilliSeconds();
774
775 m_date.assign((long)(ms / MSEC_PER_DAY));
776 m_time.assign((long)(ms % MSEC_PER_DAY));
777
778 return *this;
779}
780
782{
783 int64_t ms = (int64_t)m_date.days() * MSEC_PER_DAY
784 + (int64_t)m_time.totalMilliSeconds()
785 - iv.totalMilliSeconds();
786
787 m_date.assign((long)(ms / MSEC_PER_DAY));
788 m_time.assign((long)(ms % MSEC_PER_DAY));
789
790 return *this;
791}
792
794{
795 DateTime dtResult = dt;
796 dtResult += iv;
797 return dtResult;
798}
799
801{
802 return operator + (dt, iv);
803}
804
806{
807 DateTime dtResult = dt;
808 dtResult -= iv;
809
810 return dtResult;
811}
812
814{
815 Interval ivResult(
816 (int64_t)dt1.date().days() * MSEC_PER_DAY
817 + (int64_t)dt1.time().totalMilliSeconds()
818 - (int64_t)dt2.date().days() * MSEC_PER_DAY
819 - (int64_t)dt2.time().totalMilliSeconds()
820 );
821
822 return ivResult;
823}
824
825// Date::toString() + Time::toString()
826String DateTime::toString() const
827{
828 return m_date.toString() + L" " + m_time.toString();
829}
830
831const wchar_t* DateTime::FORMAT_STRING = L"%Y-%m-%d %H:%M:%S";
832
833// strftime
834String DateTime::toStringF(const wchar_t* pszFormat) const
835{
836 if (!pszFormat)
837 pszFormat = FORMAT_STRING;
838
839 __DCL_ASSERT(*pszFormat != L'\0');
840
841 int nYear, nMonth, nDay, nHour, nMin, nSec, nMSec;
842 m_date.decode(nYear, nMonth, nDay);
843 m_time.decode(nHour, nMin, nSec, nMSec);
844
845 struct tm t;
846 t.tm_year = nYear - 1900;
847 t.tm_mon = nMonth - 1;
848 t.tm_mday = nDay;
849 t.tm_hour = nHour;
850 t.tm_min = nMin;
851 t.tm_sec = nSec;
852
853 t.tm_wday = 0;
854 t.tm_yday = 0;
855 t.tm_isdst = -1;
856
857 CharBuffer* buf = CharBuffer::create(DATETIME_FORMAT_BUFFER_SIZE);
858 size_t n = wcsftime(buf->data(), DATETIME_FORMAT_BUFFER_SIZE, pszFormat, &t);
859 __DCL_ASSERT(buf->__allocLength >= n);
860 buf->__dataLength = n;
861 __DCL_ASSERT(buf->data()[buf->__dataLength] == __T('\0'));
862
863 String r = buf;
864 buf->release();
865 return r;
866}
867
868// static members
869int DateTime::compare(const DateTime& dt1, const DateTime& dt2)
870{
871 if (dt1.m_date < dt2.m_date)
872 return -1;
873 else if (dt1.m_date == dt2.m_date) {
874 if (dt1.m_time < dt2.m_time)
875 return -1;
876 else if (dt1.m_time == dt2.m_time)
877 return 0;
878 }
879 return 1;
880}
881
883{
884#if __DCL_WINDOWS
885 SYSTEMTIME t;
886 GetSystemTime(&t);
887
888 Date dt(t.wYear, t.wMonth, t.wDay);
889 int64_t r = dt.days() * 24;
890 r = (r + t.wHour) * 60;
891 r = (r + t.wMinute) * 60;
892 r = (r + t.wSecond) * 1000;
893 r += t.wMilliseconds;
894 return r;
895#else
896 struct timeval tv;
897 gettimeofday(&tv, NULL);
898 int64_t r = tv.tv_sec * 1000;
899 r += tv.tv_usec / 1000;
900 return r;
901#endif
902}
903
905{
906 DateTime dt;
907#if __DCL_WINDOWS
908 struct _timeb t;
909 _ftime_s(&t);
910
911 dt.m_date.assign(
912 (long) (719163 + (t.time / SEC_PER_DAY)) // 1970-01-01 00:00:00 + time
913 );
914 dt.m_time.assign(
915 0,
916 0,
917 t.time % SEC_PER_DAY,
918 t.millitm
919 );
920#else
921 struct timeval tv;
922 gettimeofday(&tv, NULL);
923
924 dt.m_date.assign(
925 719163 + tv.tv_sec / SEC_PER_DAY // 1970-01-01 00:00:00 + time
926 );
927 dt.m_time.assign(
928 0,
929 0,
930 tv.tv_sec % SEC_PER_DAY,
931 tv.tv_usec / 1000
932 );
933#endif
934 return dt;
935}
936
938{
939 DateTime dt;
940#if __DCL_WINDOWS
941 struct _timeb t;
942 _ftime_s(&t);
943
944 dt.m_date.assign(
945 (long) (719163 + ((t.time - t.timezone * 60) / SEC_PER_DAY)) // 1970-01-01 00:00:00 + time
946 );
947 dt.m_time.assign(
948 0,
949 -t.timezone,
950 t.time % SEC_PER_DAY,
951 t.millitm
952 );
953#else
954 time_t timer;
955 struct tm tm;
956 ::time(&timer);
957 localtime_r(&timer, &tm);
958
959 struct timeval tv;
960 gettimeofday(&tv, NULL);
961
962 dt.m_date.assign(
963 719163 + (tv.tv_sec + tm.tm_gmtoff) / SEC_PER_DAY // 1970-01-01 00:00:00 + time
964 );
965 dt.m_time.assign(
966 0,
967 0,
968 tv.tv_sec % SEC_PER_DAY + tm.tm_gmtoff,
969 tv.tv_usec / 1000
970 );
971#endif
972 return dt;
973}
974
975#if 0
976DateTime DateTime::parseF(
977 const char* pszDateTimeString,
978 const char* pszFormat
980{
981 __DCL_ASSERT(pszDateTimeString != NULL && *pszDateTimeString != '\0');
982 __DCL_ASSERT(pszFormat != NULL && *pszFormat != '\0');
983
984 struct tm tm;
985 memset(&tm, 0, sizeof(tm));
986 const char* p = strptime(pszDateTimeString, pszFormat, &tm);
987 if (p == NULL) {
988 throw new ParseException(L"no match to format");
989 }
990
991 if (*p != '\0') {
992 throw new ParseException(
993 L"extra data",
994 p - pszDateTimeString
995 );
996
997 }
998
999 DateTime dt(
1000 tm.tm_year + 1900,
1001 tm.tm_mon + 1,
1002 tm.tm_mday,
1003 tm.tm_hour,
1004 tm.tm_min,
1005 tm.tm_sec
1006 );
1007
1008 return dt;
1009}
1010#endif
1011
1012__DCL_END_NAMESPACE
#define __THIS_FILE__
Definition _trace.h:14
#define NULL
Definition Config.h:340
#define DCLCAPI
Definition Config.h:100
wchar_t char_t
Definition Config.h:275
#define __DCL_THROWS1(e)
Definition Config.h:167
#define MSEC_PER_HOUR
Definition DateTime.cpp:392
#define SEC_PER_DAY
Definition DateTime.cpp:389
#define AD_START
Definition DateTime.cpp:60
#define BC_END
Definition DateTime.cpp:61
#define MSEC_PER_DAY
Definition DateTime.cpp:390
DCLCAPI Interval operator-(const Interval &iv1, const Interval &iv2)
Definition DateTime.cpp:613
DCLCAPI Date operator+(const Date &d, long nDays)
Definition DateTime.cpp:178
#define MSEC_PER_MIN
Definition DateTime.cpp:394
#define DATETIME_FORMAT_BUFFER_SIZE
Definition DateTime.h:21
#define __DCL_ASSERT(expr)
Definition Object.h:371
#define __T(str)
Definition Object.h:44
ByteString r
ByteBuffer * buf
void CharsetConvertException *size_t n
Definition SQLField.cpp:253
return result
void assign(int nYear, int nMonth, int nDay)
Definition DateTime.cpp:49
void decode(int &nYear, int &nMonth, int &nDay) const
Definition DateTime.cpp:185
const Date & operator--()
Definition DateTime.cpp:112
static bool isLeapYear(int nYear)
Definition DateTime.cpp:370
long days() const
Definition DateTime.cpp:74
int day() const
Definition DateTime.cpp:204
long m_nJDay
Definition DateTime.h:77
static bool isValid(int y, int m, int d)
Definition DateTime.cpp:350
int daysInYear() const
Definition DateTime.cpp:237
int month() const
Definition DateTime.cpp:197
static const wchar_t * FORMAT_STRING
Definition DateTime.h:66
String toString() const
Definition DateTime.cpp:247
String toStringF(const wchar_t *pszFormat=NULL) const
Definition DateTime.cpp:256
const Date & operator++()
Definition DateTime.cpp:86
int dayOfWeek() const
Definition DateTime.cpp:211
int daysInMonth() const
Definition DateTime.cpp:227
static long convertGregorianToJulian(int nYear, int nMonth, int nDay)
Definition DateTime.cpp:285
static void convertJulianToGregorian(long uJulianDays, int &nYear, int &nMonth, int &nDay)
Definition DateTime.cpp:313
Date()
Definition DateTime.cpp:29
int year() const
Definition DateTime.cpp:190
const Date & operator-=(long nDays)
Definition DateTime.cpp:171
const Date & operator=(const Date &src)
Definition DateTime.cpp:138
const Date & operator+=(long nDays)
Definition DateTime.cpp:144
int dayOfYear() const
Definition DateTime.cpp:216
Time m_time
Definition DateTime.h:265
void assign(time_t time)
Definition DateTime.cpp:723
Date m_date
Definition DateTime.h:264
Time & time()
Definition DateTime.inl:162
String toString() const
Definition DateTime.cpp:826
static int compare(const DateTime &dt1, const DateTime &dt2)
Definition DateTime.cpp:869
String toStringF(const wchar_t *pszFormat=NULL) const
Definition DateTime.cpp:834
const DateTime & operator+=(const Interval &iv)
Definition DateTime.cpp:769
const DateTime & operator-=(const Interval &iv)
Definition DateTime.cpp:781
const DateTime & operator=(const DateTime &src)
Definition DateTime.cpp:761
static const wchar_t * FORMAT_STRING
Definition DateTime.h:236
static DateTime getCurrentUTCTime()
Definition DateTime.cpp:904
static int64_t getCurrentTimeMillis()
Definition DateTime.cpp:882
Date & date()
Definition DateTime.inl:152
static DateTime getCurrentLocalTime()
Definition DateTime.cpp:937
long days() const
Definition DateTime.cpp:637
int64_t totalHours() const
Definition DateTime.cpp:662
int64_t totalMinutes() const
Definition DateTime.cpp:667
int hour() const
Definition DateTime.cpp:642
int64_t totalSeconds() const
Definition DateTime.cpp:672
const Interval & operator-=(const Interval &iv)
Definition DateTime.cpp:600
const Interval & operator+=(const Interval &iv)
Definition DateTime.cpp:593
String toString() const
Definition DateTime.cpp:677
const Interval & operator=(const Interval &src)
Definition DateTime.cpp:586
void assign(int nDays, int nMilliSeconds)
Definition DateTime.cpp:564
int minute() const
Definition DateTime.cpp:647
int64_t m_nMilliSeconds
Definition DateTime.h:200
void decode(long &nDays, int &nHours, int &nMinutes, int &nSeconds, int &nMilliSeconds) const
Definition DateTime.cpp:619
int64_t totalMilliSeconds() const
Definition DateTime.inl:116
int msecond() const
Definition DateTime.cpp:657
int second() const
Definition DateTime.cpp:652
const Time & operator-=(long nMilliSeconds)
Definition DateTime.cpp:442
int hour() const
Definition DateTime.cpp:467
const Time & operator=(const Time &src)
Definition DateTime.cpp:426
int second() const
Definition DateTime.cpp:477
static const wchar_t * FORMAT_STRING
Definition DateTime.h:129
void decode(int &nHour, int &nMin, int &nSec, int &nMSec) const
Definition DateTime.cpp:459
int msecond() const
Definition DateTime.cpp:482
int minute() const
Definition DateTime.cpp:472
void assign(int nHour, int nMin, int nSec, int nMSec=0)
Definition DateTime.cpp:406
String toString() const
Definition DateTime.cpp:488
static bool isValid(int nHour, int nMin, int nSec, int nMSec)
Definition DateTime.cpp:525
long totalMilliSeconds() const
Definition DateTime.inl:65
const Time & operator+=(long nMilliSeconds)
Definition DateTime.cpp:432
String toStringF(const wchar_t *pszFormat=NULL)
Definition DateTime.cpp:500
unsigned long m_uMilliSeconds
Definition DateTime.h:139