33 #include <Pt/String.h>
40 class SerializationInfo;
61 PT_API std::string dateToString(
const Date& date);
64 PT_API Date dateFromString(
const std::string& s);
67 PT_API
void greg2jul(
unsigned& jd,
int y,
int m,
int d);
70 PT_API
void jul2greg(
unsigned jd,
int& y,
int& m,
int& d);
108 Jan = 1, Feb, Mar, Apr, May, Jun,
109 Jul, Aug, Sep, Oct, Nov, Dec
114 Sun = 0, Mon, Tue, Wed, Thu, Fri, Sat
204 : _julian(date._julian)
212 Date(
int y,
unsigned m,
unsigned d)
215 greg2jul(_julian, y, m, d);
220 explicit Date(
unsigned julianDays)
221 : _julian(julianDays)
227 { _julian = date._julian;
return *
this; }
244 void set(
int y,
unsigned m,
unsigned d)
246 greg2jul(_julian, y, m, d);
255 unsigned day()
const;
259 unsigned month()
const;
291 unsigned m = 0, d = 0;
296 unsigned deltaM =
static_cast<unsigned>( std::abs(n) % 12 );
334 unsigned m = 0, d = 0;
347 {
return dateToString(*
this); }
360 {
return dateFromString(s); }
365 { _julian += days;
return *
this; }
370 { _julian -= days;
return *
this; }
375 { _julian++;
return *
this; }
380 { _julian--;
return *
this; }
384 static bool isValid(
int y,
int m,
int d);
472 inline void Date::get(
int& y,
unsigned& m,
unsigned& d)
const
475 jul2greg(_julian, y, mon, day_);
483 return ((y%4==0) && (y%100!=0)) || (y%400==0);
490 jul2greg(_julian, y ,m, d);
498 jul2greg(_julian, y, m, d);
506 jul2greg(_julian, y, m, d);
513 return (_julian+1) % 7;
519 static const unsigned char monthDays[13]=
521 0,31,28,31,30,31,30,31,31,30,31,30,31
525 jul2greg(_julian, y, m, d);
538 jul2greg(_julian,y,m,d);
548 jul2greg(_julian,y,m,d);
555 if(m<1 || m>12 || d<1 || d>31)
bool operator<(const Date &a, const Date &b)
Less-than comparison operator.
Definition: Date.h:426
Core module.
Definition: Allocator.h:33
Date expressed in year, month, and day.
Definition: Date.h:104
unsigned day() const
Returns the day-part of the date.
Definition: Date.h:487
Date operator+(const Date &d, int days)
Add days to a date.
Definition: Date.h:454
unsigned month() const
Returns the month-part of the date.
Definition: Date.h:495
static const unsigned DaysOfFeb
The number of days of a February.
Definition: Date.h:135
static const unsigned DaysOfJul
The number of days of a July.
Definition: Date.h:165
static const unsigned DaysOfSep
The number of days of a September.
Definition: Date.h:175
static const unsigned DaysPerYear
The number of days of an ordinary year.
Definition: Date.h:120
Date(unsigned julianDays)
Constructs a Date from a julian day.
Definition: Date.h:220
void setJulian(unsigned d)
Sets the Date to a julian day.
Definition: Date.h:231
int operator-(const Date &a, const Date &b)
Subtract two dates.
Definition: Date.h:468
Date & operator++()
Increments the date by one day.
Definition: Date.h:374
static const unsigned DaysOfJan
The number of days of a January.
Definition: Date.h:130
Date(int y, unsigned m, unsigned d)
Constructs a Date from given values.
Definition: Date.h:212
bool operator!=(const Date &a, const Date &b)
Returns true if the dates are not equal.
Definition: Date.h:419
bool operator>(const Date &a, const Date &b)
Greater-than comparison operator.
Definition: Date.h:440
int year() const
Returns the year-part of the date.
Definition: Date.h:503
Date & operator+=(int days)
Add days to the date.
Definition: Date.h:364
Date & operator-=(int days)
Substract days from the date.
Definition: Date.h:369
unsigned daysInMonth() const
Returns the days of the month of the date.
Definition: Date.h:517
void get(int &year, unsigned &month, unsigned &day) const
Gets the year, month and day.
Definition: Date.h:472
static const unsigned DaysOfMay
The number of days of a May.
Definition: Date.h:155
static const unsigned DaysOfApr
The number of days of a April.
Definition: Date.h:150
void addDays(int n)
Adds n days to the date.
Definition: Date.h:283
static Date fromIsoString(const std::string &s)
Interprets a string as a date-string in ISO-format.
Definition: Date.h:359
static const unsigned DaysOfDec
The number of days of a December.
Definition: Date.h:190
~InvalidDate()
Destructor.
Definition: Date.h:56
bool operator<=(const Date &a, const Date &b)
Less-than-equal comparison operator.
Definition: Date.h:433
unsigned dayOfWeek() const
Return day of the week, starting with sunday.
Definition: Date.h:511
Date operator+(int days, const Date &d)
Add days to a date.
Definition: Date.h:461
static const unsigned DaysOfLeapFeb
The number of days of a February in a leap year.
Definition: Date.h:140
std::string toIsoString() const
Returns the date in ISO-format.
Definition: Date.h:346
void addMonths(int n)
Adds n months to the date.
Definition: Date.h:288
static const unsigned DaysOfOct
The number of days of a October.
Definition: Date.h:180
static const unsigned DaysPerLeapYear
The number of days of a leap year.
Definition: Date.h:125
Date(const Date &date)
Copy constructor.
Definition: Date.h:203
Date & operator--()
Decrements the date by one day.
Definition: Date.h:379
unsigned dayOfYear() const
Returns the day of the year.
Definition: Date.h:534
unsigned julian() const
Returns the Date as a julian day.
Definition: Date.h:236
static const unsigned DaysOfAug
The number of days of a August.
Definition: Date.h:170
Indicates an invalid date value.
Definition: Date.h:50
void addYears(int n)
Adds n years to the date.
Definition: Date.h:331
bool operator>=(const Date &a, const Date &b)
Greater-than-equal comparison operator.
Definition: Date.h:447
bool operator==(const Date &a, const Date &b)
Returns true if the dates are equal.
Definition: Date.h:412
static bool isValid(int y, int m, int d)
Returns true if values describe a valid date.
Definition: Date.h:553
Date & operator=(const Date &date)
Assignment operator.
Definition: Date.h:226
static const unsigned DaysOfJun
The number of days of a June.
Definition: Date.h:160
bool isLeapYear() const
Returns true if the date is in a leap year.
Definition: Date.h:545
void set(int y, unsigned m, unsigned d)
Sets the date to a year, month and day.
Definition: Date.h:244
Represents arbitrary types during serialization.
Definition: SerializationInfo.h:59
static const unsigned DaysOfMar
The number of days of a March.
Definition: Date.h:145
Date()
Default constructor.
Definition: Date.h:197
InvalidDate()
Constructor.
static const unsigned DaysOfNov
The number of days of a November.
Definition: Date.h:185