31static const _TUCHAR sDaysInMonth[12] =
32 { 31,28,31,30,31,30,31,31,30,31,30,31 };
33static const DayTy sFirstDayOfEachMonth[12] =
34 { 1,32,60,91,121,152,182,213,244,274,305,335 };
37static const tchar* DefMonthNames[12] =
38 {
_T(
"January"),
_T(
"February"),
_T(
"March"),
_T(
"April"),
_T(
"May"),
_T(
"June"),
39 _T(
"July"),
_T(
"August"),
_T(
"September"),
_T(
"October"),
_T(
"November"),
_T(
"December") };
40static const tchar* DefUCMonthNames[12] =
41 {
_T(
"JANUARY"),
_T(
"FEBRUARY"),
_T(
"MARCH"),
_T(
"APRIL"),
_T(
"MAY"),
_T(
"JUNE"),
42 _T(
"JULY"),
_T(
"AUGUST"),
_T(
"SEPTEMBER"),
_T(
"OCTOBER"),
_T(
"NOVEMBER"),
_T(
"DECEMBER") };
44static const tchar* DefWeekDayNames[7] =
45 {
_T(
"Monday"),
_T(
"Tuesday"),
_T(
"Wednesday"),
46 _T(
"Thursday"),
_T(
"Friday"),
_T(
"Saturday"),
_T(
"Sunday") };
47static const tchar* DefUCWeekDayNames[7] =
48 {
_T(
"MONDAY"),
_T(
"TUESDAY"),
_T(
"WEDNESDAY"),
49 _T(
"THURSDAY"),
_T(
"FRIDAY"),
_T(
"SATURDAY"),
_T(
"SUNDAY") };
52static const tchar** MonthNames = DefMonthNames;
53static const tchar** UCMonthNames = DefUCMonthNames;
54static const tchar** WeekDayNames = DefWeekDayNames;
55static const tchar** UCWeekDayNames = DefUCWeekDayNames;
87 Julnum =
Jday( 12, 31, year-1 ) +
static_cast<JulTy>(day);
89 Julnum = jul1901 +
static_cast<JulTy>(day);
105 Julnum =
Jday( month, day, year );
157 return static_cast<DayTy>(
FindMatch( nameOfDay.c_str(), UCWeekDayNames, 7 )+1);
170 days = sDaysInMonth[month-1];
171 if(
Leap() && month == 2)
185 unsigned d = sDaysInMonth[month-1];
205 return static_cast<MonthTy>(
FindMatch(nameOfMonth.c_str(), UCMonthNames, 12 )+1);
223 return static_cast<JulTy>(0);
234 return ((146097L*c)>>2) + ((1461*ya)>>2) + (153*m + 2)/5 + d + 1721119L;
242 return ((year & 3) == 0 && (year % 100) != 0) || (year % 400) == 0;
260 unsigned len =
static_cast<unsigned>(
::_tcslen(str));
281 if( Julnum < d.Julnum )
283 else if( Julnum > d.Julnum )
315 unsigned firstDay = sFirstDayOfEachMonth[month-1];
316 if (month > 2 &&
Leap())
324 return static_cast<unsigned>(Julnum);
337 JulTy j = Julnum - 1721119L;
338 y = (
YearTy) (((j<<2) - 1) / 146097L);
339 j = (j<<2) - 1 - 146097L*y;
341 j = ((_d<<2) + 3) / 1461;
342 _d = (_d<<2) + 3 - 1461*j;
345 _d = 5*_d - 3 - 153*m;
346 d = (
DayTy)((_d + 5)/5);
363 return dt.Julnum > Julnum ? dt : *
this;
372 return dt.Julnum < Julnum ? dt : *
this;
411 if( desiredDayOfWeek > thisDayOfWeek )
412 thisDayOfWeek += 7 - desiredDayOfWeek;
414 thisDayOfWeek -= desiredDayOfWeek;
425 return DayTy(((((julnum+1)%7)+6)%7)+1);
441 int accept_digits(LPCTSTR str)
449 int skip(LPCTSTR picture,
tchar c)
452 while (_totlower(picture[n]) == c)
457 int parse_number(LPCTSTR& str, LPCTSTR& picture,
tchar format_char)
459 const int n = accept_digits(str);
462 picture += skip(picture, format_char);
471void TDate::ParseFrom(LPCTSTR str, LPCTSTR format)
473 int day, month, year;
474 Julnum = day = month = year = 0;
476 TProfile p(
_T(
"intl"));
477 tstring shortFmt = p.GetString(
_T(
"sShortDate"),
_T(
"MM/dd/yyyy"));
478 LPCTSTR picture = format ? format : shortFmt.c_str();
480 while (*picture && *str) {
481 tchar c =
static_cast<tchar>(_totlower(*picture));
484 day = parse_number(str, picture, c);
488 month = parse_number(str, picture, c);
492 year = parse_number(str, picture, c);
502 Julnum =
Jday(month, day, year);
513 const tchar*** Names[] = { &MonthNames, &UCMonthNames,
514 &WeekDayNames, &UCWeekDayNames,
516 const tchar*** DefNames[] = {
517 (
const tchar***)&DefMonthNames, (
const tchar***)&DefUCMonthNames,
518 (
const tchar***)&DefWeekDayNames, (
const tchar***)&DefUCWeekDayNames,
521 *(Names[type]) = names;
523 *(Names[type]) = *(DefNames[type]);
532 const tchar** Names[] = { MonthNames, UCMonthNames,
533 WeekDayNames, UCWeekDayNames,
535 return Names[type][index];
543 return TDate(dt.Julnum + dd);
551 return TDate(dt.Julnum + dd);
559 return TDate(dt.Julnum - dd);
The TDate class represents a date.
YearTy Year() const
Returns the year of this TDate.
static int LeapYear(YearTy year)
unsigned Hash() const
Returns a hash value for the date.
int DaysInMonth(MonthTy month=0) const
TDate()
Construct a TDate with the current date.
static LPCTSTR MonthName(MonthTy monthNumber)
Returns the string name for the given monthNumber (1-12).
static int AssertIndexOfMonth(MonthTy m)
Returns 1 if m is between 1 and 12 inclusive, otherwise returns 0.
int Leap() const
leap year?
static DayTy DaysInYear(YearTy)
Returns the number of days in the year specified (365 or 366).
TDate Max(const TDate &dt) const
Compares this TDate with dt and returns the date with the greater Julian number.
int CompareTo(const TDate &) const
Returns 1 if the target TDate is greater than parameter TDate, -1 if the target is less than the para...
static int AssertWeekDayNumber(DayTy d)
Returns 1 if d is between 1 and 7 inclusive, otherwise returns 0.
static MonthTy IndexOfMonth(const tstring &monthName)
Returns the number, 1-12, of the month named nameOfMonth.
static LPCTSTR DayName(DayTy weekDayNumber)
Returns a string name for the weekday number.
DayTy FirstDayOfMonth() const
Returns the number of the first day of the month for this TDate.
static void SetIntlNames(TDateType type, const tchar **names)
static const tchar * GetIntlName(TDateType type, int index)
MonthTy Month() const
Returns the month of this TDate.
TSystemTime GetSystemTime() const
static int DayWithinMonth(MonthTy, DayTy, YearTy)
Returns 1 if the given day (1-31) is within the given month for the given year.
DayTy WeekDay(DayTy day=0) const
Returns 1 (Monday) through 7 (Sunday).
TDate Min(const TDate &dt) const
Compares this TDate with dt and returns the date with the lesser Julian number.
static DayTy DayOfWeek(const tstring &dayName)
Return the number, 1-7, of the day of the week named nameOfDay.
DayTy Day() const
Returns the day of the year (1-365).
static JulTy Jday(MonthTy, DayTy, YearTy)
Convert Gregorian calendar date to the corresponding Julian day number j.
TDate Previous(const tstring &dayName) const
Return date of previous dayName.
DayTy DayOfMonth() const
Returns the day (1-31) of the month of this TDate.
TSystemTime is a class derived from the structure SYSTEMTIME.
static TSystemTime LocalTime()
The TTime class encapsulates time functions and characteristics.
int IsValid() const
Returns 1 if this TTime object contains a valid time, 0 otherwise.
Object Windows Library (OWLNext Core).
const uint32 SECONDS_IN_DAY
unsigned YearTy
Year type.
_OWLSTATICFUNC(static int) FindMatch(const tchar *str
TTime operator+(const TTime &t, long s)
Adds s seconds to time t.
TTime operator-(const TTime &t, long s)
Performs subtraction, in seconds, between s and t.
unsigned long JulTy
Julian calendar type.
FindMatch(const tchar *str, const tchar **candidates, int icand)
const tchar ** candidates
unsigned MonthTy
Month type.
Definition of TProfile class.
Definition of class TString, a flexible universal string envelope class.
Classes for window system structure and type encapsulation.