33 #include <Pt/String.h>
39 class SerializationInfo;
60 PT_API std::string dateToString(
const Date& date);
63 PT_API Date dateFromString(
const std::string& s);
66 PT_API
void greg2jul(
unsigned& jd,
int y,
int m,
int d);
69 PT_API
void jul2greg(
unsigned jd,
int& y,
int& m,
int& d);
107 Jan = 1, Feb, Mar, Apr, May, Jun,
108 Jul, Aug, Sep, Oct, Nov, Dec
113 Sun = 0, Mon, Tue, Wed, Thu, Fri, Sat
203 : _julian(date._julian)
211 Date(
int y,
unsigned m,
unsigned d)
214 greg2jul(_julian, y, m, d);
219 explicit Date(
unsigned julianDays)
220 : _julian(julianDays)
226 { _julian = date._julian;
return *
this; }
243 void set(
int y,
unsigned m,
unsigned d)
245 greg2jul(_julian, y, m, d);
250 void get(
int&
year,
unsigned&
month,
unsigned&
day)
const;
254 unsigned day()
const;
258 unsigned month()
const;
290 unsigned m = 0, d = 0;
310 unsigned m = 0, d = 0;
323 {
return dateToString(*
this); }
336 {
return dateFromString(s); }
341 { _julian += days;
return *
this; }
346 { _julian -= days;
return *
this; }
351 { _julian++;
return *
this; }
356 { _julian--;
return *
this; }
360 static bool isValid(
int y,
int m,
int d);
375 PT_API
void operator >>=(
const SerializationInfo& si, Date& date);
381 PT_API
void operator <<=(SerializationInfo& si,
const Date& date);
448 inline void Date::get(
int& y,
unsigned& m,
unsigned& d)
const
451 jul2greg(_julian, y, mon, day_);
459 return ((y%4==0) && (y%100!=0)) || (y%400==0);
466 jul2greg(_julian, y ,m, d);
474 jul2greg(_julian, y, m, d);
482 jul2greg(_julian, y, m, d);
489 return (_julian+1) % 7;
495 static const unsigned char monthDays[13]=
497 0,31,28,31,30,31,30,31,31,30,31,30,31
501 jul2greg(_julian, y, m, d);
514 jul2greg(_julian,y,m,d);
524 jul2greg(_julian,y,m,d);
531 if(m<1 || m>12 || d<1 || d>31)
bool isLeapYear() const
Returns true if the date is in a leap year.
Definition: Date.h:521
static const unsigned DaysOfLeapFeb
The number of days of a February in a leap year.
Definition: Date.h:139
static const unsigned DaysPerLeapYear
The number of days of a leap year.
Definition: Date.h:124
void addMonths(int n)
Adds n months to the date.
Definition: Date.h:287
static const unsigned DaysOfOct
The number of days of a October.
Definition: Date.h:179
Date & operator--()
Decrements the date by one day.
Definition: Date.h:355
unsigned daysInMonth() const
Returns the days of the month of the date.
Definition: Date.h:493
bool operator>=(const Date &a, const Date &b)
Greater-than-equal comparison operator.
Definition: Date.h:423
static const unsigned DaysOfAug
The number of days of a August.
Definition: Date.h:169
bool operator==(const Date &a, const Date &b)
Returns true if the dates are equal.
Definition: Date.h:388
Date expressed in year, month, and day.
Definition: Date.h:102
void addYears(int n)
Adds n years to the date.
Definition: Date.h:307
Date & operator=(const Date &date)
Assignment operator.
Definition: Date.h:225
void get(int &year, unsigned &month, unsigned &day) const
Gets the year, month and day.
Definition: Date.h:448
unsigned month() const
Returns the month-part of the date.
Definition: Date.h:471
static bool isValid(int y, int m, int d)
Returns true if values describe a valid date.
Definition: Date.h:529
unsigned julian() const
Returns the Date as a julian day.
Definition: Date.h:235
static const unsigned DaysOfJun
The number of days of a June.
Definition: Date.h:159
void set(int y, unsigned m, unsigned d)
Sets the date to a year, month and day.
Definition: Date.h:243
~InvalidDate()
Destructor.
Definition: Date.h:55
bool operator<(const Date &a, const Date &b)
Less-than comparison operator.
Definition: Date.h:402
static const unsigned DaysOfNov
The number of days of a November.
Definition: Date.h:184
static const unsigned DaysOfMar
The number of days of a March.
Definition: Date.h:144
Date()
Default constructor.
Definition: Date.h:196
static const unsigned DaysOfFeb
The number of days of a February.
Definition: Date.h:134
static const unsigned DaysOfJul
The number of days of a July.
Definition: Date.h:164
static const unsigned DaysOfSep
The number of days of a September.
Definition: Date.h:174
Date(unsigned julianDays)
Constructs a Date from a julian day.
Definition: Date.h:219
unsigned day() const
Returns the day-part of the date.
Definition: Date.h:463
void setJulian(unsigned d)
Sets the Date to a julian day.
Definition: Date.h:230
Date operator+(const Date &d, int days)
Add days to a date.
Definition: Date.h:430
Indicates an invalid date value.
Definition: Date.h:48
static const unsigned DaysOfJan
The number of days of a January.
Definition: Date.h:129
Date(int y, unsigned m, unsigned d)
Constructs a Date from given values.
Definition: Date.h:211
bool operator!=(const Date &a, const Date &b)
Returns true if the dates are not equal.
Definition: Date.h:395
unsigned dayOfYear() const
Returns the day of the year.
Definition: Date.h:510
static const unsigned DaysPerYear
The number of days of an ordinary year.
Definition: Date.h:119
int operator-(const Date &a, const Date &b)
Subtract two dates.
Definition: Date.h:444
unsigned dayOfWeek() const
Return day of the week, starting with sunday.
Definition: Date.h:487
Date & operator++()
Increments the date by one day.
Definition: Date.h:350
Date & operator-=(int days)
Substract days from the date.
Definition: Date.h:345
bool operator>(const Date &a, const Date &b)
Greater-than comparison operator.
Definition: Date.h:416
int year() const
Returns the year-part of the date.
Definition: Date.h:479
Date & operator+=(int days)
Add days to the date.
Definition: Date.h:340
static const unsigned DaysOfMay
The number of days of a May.
Definition: Date.h:154
static const unsigned DaysOfApr
The number of days of a April.
Definition: Date.h:149
std::string toIsoString() const
Returns the date in ISO-format.
Definition: Date.h:322
void addDays(int n)
Adds n days to the date.
Definition: Date.h:282
bool operator<=(const Date &a, const Date &b)
Less-than-equal comparison operator.
Definition: Date.h:409
static Date fromIsoString(const std::string &s)
Interprets a string as a date-string in ISO-format.
Definition: Date.h:335
static const unsigned DaysOfDec
The number of days of a December.
Definition: Date.h:189
Date(const Date &date)
Copy constructor.
Definition: Date.h:202
Date operator+(int days, const Date &d)
Add days to a date.
Definition: Date.h:437