DCL 3.7.4
Loading...
Searching...
No Matches
Date Class Reference

#include <DateTime.h>

Public Member Functions

 Date ()
 Date (const Date &_src)
 Date (int _year, int _month, int _day)
void assign (int _year, int _month, int _day)
 Date (long _days)
void assign (long _days)
long days () const
const Dateoperator++ ()
const Date operator++ (int)
const Dateoperator-- ()
const Date operator-- (int)
const Dateoperator= (const Date &_src)
const Dateoperator+= (long _days)
const Dateoperator-= (long _days)
void decode (int &_year, int &_month, int &_day) const
int year () const
int month () const
int day () const
int dayOfWeek () const
int dayOfYear () const
int daysInMonth () const
int daysInYear () const
String toString () const
String toStringF (const wchar_t *_format=NULL) const

Static Public Member Functions

static bool isValid (int y, int m, int d)
static bool isLeapYear (int _year)

Static Public Attributes

static const wchar_t * FORMAT_STRING = L"%Y-%m-%d"

Static Protected Member Functions

static long convertGregorianToJulian (int _year, int _month, int _day)
static void convertJulianToGregorian (long uJulianDays, int &_year, int &_month, int &_day)

Protected Attributes

long __jday

Detailed Description

Definition at line 24 of file DateTime.h.

Constructor & Destructor Documentation

◆ Date() [1/4]

__DCL_BEGIN_NAMESPACE Date::Date ( )

Definition at line 29 of file DateTime.cpp.

30{
31 __jday = 0;
32}
long __jday
Definition DateTime.h:75

◆ Date() [2/4]

Date::Date ( const Date & _src)

Definition at line 34 of file DateTime.cpp.

35{
36 __jday = _src.__jday;
37}

◆ Date() [3/4]

Date::Date ( int _year,
int _month,
int _day )

Definition at line 39 of file DateTime.cpp.

40{
41 assign(_year, _month, _day);
42}
void assign(int _year, int _month, int _day)
Definition DateTime.cpp:49

◆ Date() [4/4]

Date::Date ( long _days)

Definition at line 44 of file DateTime.cpp.

45{
46 assign(_days);
47}

Member Function Documentation

◆ assign() [1/2]

void Date::assign ( int _year,
int _month,
int _day )

Definition at line 49 of file DateTime.cpp.

50{
51 __DCL_ASSERT(Date::isValid(_year, _month, _day));
52
54 _year,
55 _month,
56 _day
57 );
58}
#define __DCL_ASSERT(expr)
Definition Object.h:394
static long convertGregorianToJulian(int _year, int _month, int _day)
Definition DateTime.cpp:293
static bool isValid(int y, int m, int d)
Definition DateTime.cpp:358

◆ assign() [2/2]

void Date::assign ( long _days)

Definition at line 63 of file DateTime.cpp.

64{
65 if (_days < 0)
66 __jday = _days + BC_END + 1;
67 else if (_days > 0)
68 __jday = _days + AD_START - 1;
69 else
70 // set NULL date
71 __jday = _days;
72}
#define AD_START
Definition DateTime.cpp:60
#define BC_END
Definition DateTime.cpp:61

◆ convertGregorianToJulian()

long Date::convertGregorianToJulian ( int _year,
int _month,
int _day )
staticprotected

Definition at line 293 of file DateTime.cpp.

296{
297 if (_y == 0) {
298 __DCL_ASSERT(_m == 0 && _d == 0);
299 return 0;
300 }
301
302 _y += 600000;
303
304 int c, ya;
305 if (_m > 2)
306 _m -= 3;
307 else {
308 _m += 9;
309 _y--;
310 }
311 c = _y / 100;
312 ya = _y - 100 * c;
313
314 return (146097 * c) / 4
315 + (1461 * ya) / 4
316 + (153 * _m + 2) / 5
317 + _d
318 + 1721119;
319}

◆ convertJulianToGregorian()

void Date::convertJulianToGregorian ( long uJulianDays,
int & _year,
int & _month,
int & _day )
staticprotected

Definition at line 321 of file DateTime.cpp.

325{
326 if (_j == 0) {
327 _y = 0;
328 _m = 0;
329 _d = 0;
330 }
331 else {
332 _j -= 1721119;
333
334 _y = (4 * _j - 1) / 146097;
335 _j = 4 * _j - 1 - 146097 * _y;
336 _d = _j / 4;
337
338 _j = (4 * _d + 3) / 1461;
339 _d = 4 * _d + 3 - 1461 * _j;
340 _d = (_d + 4) / 4;
341
342 _m = (5 * _d - 3) / 153;
343 _d = 5 * _d - 3 - 153 * _m;
344 _d = (_d + 5 ) / 5;
345
346 _y = 100 * _y + _j;
347 if (_m < 10)
348 _m += 3;
349 else {
350 _m -= 9;
351 _y++;
352 }
353
354 _y -= 600000;
355 }
356}

◆ day()

int Date::day ( ) const

Definition at line 203 of file DateTime.cpp.

204{
205 int year, month, day;
207 return day;
208}
int day() const
Definition DateTime.cpp:203
static void convertJulianToGregorian(long uJulianDays, int &_year, int &_month, int &_day)
Definition DateTime.cpp:321
int month() const
Definition DateTime.cpp:196
int year() const
Definition DateTime.cpp:189

◆ dayOfWeek()

int Date::dayOfWeek ( ) const

Definition at line 210 of file DateTime.cpp.

211{
212 return (((__jday + 1) % 7) + 7) % 7 + 1;
213}

◆ dayOfYear()

int Date::dayOfYear ( ) const

Definition at line 215 of file DateTime.cpp.

216{
217 return __jday - convertGregorianToJulian(year(), 1, 1) + 1;
218}

◆ days()

long Date::days ( ) const

Definition at line 74 of file DateTime.cpp.

75{
76 if (__jday <= BC_END)
77 return __jday - BC_END - 1;
78 else if (__jday >= AD_START)
79 return __jday - AD_START + 1;
80 else {
81 __DCL_ASSERT(__jday == 0);
82 return __jday;
83 }
84}

◆ daysInMonth()

int Date::daysInMonth ( ) const

Definition at line 226 of file DateTime.cpp.

227{
228 int year, month, day;
230 if (month == 2 && isLeapYear(year))
231 return 29;
232
233 return __monthDays__[month];
234}
static bool isLeapYear(int _year)
Definition DateTime.cpp:378

◆ daysInYear()

int Date::daysInYear ( ) const

Definition at line 236 of file DateTime.cpp.

237{
238 int year, month, day;
240
241 if (isLeapYear(year))
242 return 366;
243 return 365;
244}

◆ decode()

void Date::decode ( int & _year,
int & _month,
int & _day ) const

Definition at line 184 of file DateTime.cpp.

185{
186 convertJulianToGregorian(__jday, _year, _month, _day);
187}

◆ isLeapYear()

bool Date::isLeapYear ( int _year)
static

Definition at line 378 of file DateTime.cpp.

379{
380 return (_y % 4 == 0 && _y % 100 != 0) || _y % 400 == 0;
381}

◆ isValid()

bool Date::isValid ( int y,
int m,
int d )
static

Definition at line 358 of file DateTime.cpp.

359{
360 if (_y == 0) {
361 // null date
362 if (_m == 0 && _d == 0)
363 return true;
364 }
365 else {
366 if ((-9999 <= _y && _y <= 9999) &&
367 (0 < _m && _m <= 12)
368 && (0 < _d)) {
369 if (_m == 2 && _d == 29)
370 return Date::isLeapYear(_y);
371 else
372 return _d <= __monthDays__[_m];
373 }
374 }
375 return false;
376}

◆ month()

int Date::month ( ) const

Definition at line 196 of file DateTime.cpp.

197{
198 int year, month, day;
200 return month;
201}

◆ operator++() [1/2]

const Date & Date::operator++ ( )

Definition at line 86 of file DateTime.cpp.

87{
88 __DCL_ASSERT(__jday != 0);
89
90 if (__jday == BC_END)
92 else
93 __jday++;
94
95 return *this;
96}

◆ operator++() [2/2]

const Date Date::operator++ ( int )

Definition at line 98 of file DateTime.cpp.

99{
100 __DCL_ASSERT(__jday != 0);
101
102 Date r = *this;
103
104 if (__jday == BC_END)
106 else
107 __jday++;
108
109 return r;
110}
IOException *size_t r
Definition MediaInfo.cpp:82
Date()
Definition DateTime.cpp:29

◆ operator+=()

const Date & Date::operator+= ( long _days)

Definition at line 144 of file DateTime.cpp.

145{
146 __DCL_ASSERT(__jday != 0);
147
148 if (__jday <= BC_END) {
149 __jday += _days - BC_END;
150
151 if (__jday <= 0)
152 __jday += BC_END;
153 else
154 __jday += AD_START - 1;
155 }
156 else {
158
159 __jday += _days - AD_START;
160
161 if (__jday >= 0)
162 __jday += AD_START;
163 else
164 __jday += BC_END + 1;
165 }
166
167 return *this;
168}

◆ operator--() [1/2]

const Date & Date::operator-- ( )

Definition at line 112 of file DateTime.cpp.

113{
114 __DCL_ASSERT(__jday != 0);
115
116 if (__jday == AD_START)
117 __jday = BC_END;
118 else
119 __jday--;
120
121 return *this;
122}

◆ operator--() [2/2]

const Date Date::operator-- ( int )

Definition at line 124 of file DateTime.cpp.

125{
126 __DCL_ASSERT(__jday != 0);
127
128 Date r = *this;
129
130 if (__jday == AD_START)
131 __jday = BC_END;
132 else
133 __jday--;
134
135 return r;
136}

◆ operator-=()

const Date & Date::operator-= ( long _days)

Definition at line 170 of file DateTime.cpp.

171{
172 __DCL_ASSERT(__jday != 0);
173
174 return operator += (-_days);
175}
const Date & operator+=(long _days)
Definition DateTime.cpp:144

◆ operator=()

const Date & Date::operator= ( const Date & _src)

Definition at line 138 of file DateTime.cpp.

139{
140 __jday = _src.__jday;
141 return *this;
142}

◆ toString()

String Date::toString ( ) const

Definition at line 251 of file DateTime.cpp.

252{
253 int year, month, day;
254 decode(year, month, day);
255 String r = String::format(L"%04d-%02d-%02d", __ABS(year), month, day);
256 if (year < 0) {
257 r = r + L" BC";
258 }
259 return r;
260}
#define __ABS(n)
Definition MyParam.cpp:145
void decode(int &_year, int &_month, int &_day) const
Definition DateTime.cpp:184

◆ toStringF()

String Date::toStringF ( const wchar_t * _format = NULL) const

Definition at line 264 of file DateTime.cpp.

265{
266 if (!_format)
267 _format = FORMAT_STRING;
268
269 __DCL_ASSERT(*_format != L'\0');
270
271 int year, month, day;
272 decode(year, month, day);
273
274 struct tm _time;
275 memset(&_time, 0, sizeof(struct tm));
276 _time.tm_year = year - 1900;
277 _time.tm_mon = month - 1;
278 _time.tm_mday = day;
279 _time.tm_isdst = -1;
280
281 CharBuffer* buf = CharBuffer::create(DATETIME_FORMAT_BUFFER_SIZE);
282 size_t n = wcsftime(buf->data(), DATETIME_FORMAT_BUFFER_SIZE, _format, &_time);
283 __DCL_ASSERT(buf->__allocLength >= n);
284 buf->__dataLength = n;
285
286 String r = buf;
287 buf->release();
288 return r;
289}
#define DATETIME_FORMAT_BUFFER_SIZE
Definition DateTime.h:21
static const wchar_t * FORMAT_STRING
Definition DateTime.h:66

◆ year()

int Date::year ( ) const

Definition at line 189 of file DateTime.cpp.

190{
191 int year, month, day;
193 return year;
194}

Member Data Documentation

◆ __jday

long Date::__jday
protected

Definition at line 75 of file DateTime.h.

◆ FORMAT_STRING

const wchar_t * Date::FORMAT_STRING = L"%Y-%m-%d"
static

Definition at line 66 of file DateTime.h.


The documentation for this class was generated from the following files: