78G::Date::Date(
int year , Date::Month month ,
int day_of_month , std::nothrow_t ) noexcept :
80 m_month(
static_cast<int>(month)) ,
83 m_day = std::max( 1 , std::min(m_day,31) ) ;
84 m_month = std::max( 1 , std::min(m_month,12) ) ;
85 m_year = std::max( yearLowerLimit() , std::min(m_year,yearUpperLimit()) ) ;
92 m_month(static_cast<int>(month)) ,
102 m_month = tm.
month() ;
106void G::Date::check()
const
109 m_year >= yearLowerLimit() &&
110 m_year <= yearUpperLimit() &&
116 throw DateError(
"out of range" ) ;
122 std::ostringstream ss ;
123 if(
format == Format::yyyy_mm_dd_slash )
125 ss << yyyy() <<
"/" << mm() <<
"/" << dd() ;
127 else if(
format == Format::yyyy_mm_dd )
129 ss << yyyy() << mm() << dd() ;
131 else if(
format == Format::mm_dd )
137 G_ASSERT( !
"enum error" ) ;
150 return Str::fromInt(std::min(99,std::max(0,m_day))+100).substr(1U) ;
155 return Str::fromInt(std::min(99,std::max(0,m_month))+100).substr(1U) ;
160 return Str::fromInt(std::min(9999,std::max(0,m_year))+10000).substr(1U) ;
165 if( ! m_weekday_set )
168 const_cast<Date*
>(
this)->m_weekday_set =
true ;
169 const_cast<Date*
>(
this)->m_weekday = Weekday(bdt.
wday()) ;
176 Weekday d = weekday() ;
177 const char * p =
"" ;
178 if( d == Weekday::sunday ) p = brief ?
"Sun" :
"Sunday" ;
179 else if( d == Weekday::monday ) p = brief ?
"Mon" :
"Monday" ;
180 else if( d == Weekday::tuesday ) p = brief ?
"Tue" :
"Tuesday" ;
181 else if( d == Weekday::wednesday ) p = brief ?
"Wed" :
"Wednesday" ;
182 else if( d == Weekday::thursday ) p= brief ?
"Thu" :
"Thursday" ;
183 else if( d == Weekday::friday ) p = brief ?
"Fri" :
"Friday" ;
184 else if( d == Weekday::saturday ) p = brief ?
"Sat" :
"Saturday" ;
190 return Month(m_month) ;
196 const char * p =
"" ;
197 if( m == Month::january ) p = brief ?
"Jan" :
"January" ;
198 else if( m == Month::february ) p = brief ?
"Feb" :
"February" ;
199 else if( m == Month::march ) p = brief ?
"Mar" :
"March" ;
200 else if( m == Month::april ) p = brief ?
"Apr" :
"April" ;
201 else if( m == Month::may ) p =
"May" ;
202 else if( m == Month::june ) p = brief ?
"Jun" :
"June" ;
203 else if( m == Month::july ) p = brief ?
"Jul" :
"July" ;
204 else if( m == Month::august ) p = brief ?
"Aug" :
"August" ;
205 else if( m == Month::september ) p = brief ?
"Sep" :
"September" ;
206 else if( m == Month::october ) p = brief ?
"Oct" :
"October" ;
207 else if( m == Month::november ) p = brief ?
"Nov" :
"November" ;
208 else if( m == Month::december ) p = brief ?
"Dec" :
"December" ;
229 if( m_day == (lastDay(m_month,m_year)+1) )
241 if( m_weekday == Weekday::saturday )
242 m_weekday = Weekday::sunday ;
244 m_weekday =
static_cast<Weekday
>(
static_cast<int>(m_weekday)+1) ;
272 m_day = lastDay( m_month , m_year ) ;
280 if( m_weekday == Weekday::sunday )
281 m_weekday = Weekday::saturday ;
283 m_weekday =
static_cast<Weekday
>(
static_cast<int>(m_weekday)-1) ;
288int G::Date::lastDay(
int month ,
int year )
301 else if( month == 2 )
303 end = isLeapYear(year) ? 29 : 28 ;
308bool G::Date::isLeapYear(
int y )
310 return y >= 1800 && ( y % 400 == 0 || ( y % 100 != 0 && y % 4 == 0 ) ) ;
316 year() == other.
year() &&
317 month() == other.
month() &&
324 return !( other == *this ) ;
An encapsulation of 'struct std::tm'.
int wday() const
Returns week day where sunday=0 and saturday=6.
int day() const
Returns the 1..31 month-day value.
static BrokenDownTime midday(int year, int month, int day)
Factory function for midday on the given date.
int month() const
Returns the 1..12 month value.
int year() const
Returns the four-digit year value.
An overload discriminator class for Date constructors.
A day-month-year date class.
Date()
Default constructor for the current date in the UTC timezone.
Date & operator--()
Decrements the date by one day.
std::string monthName(bool brief=false) const
Returns the month as a string (in english).
std::string weekdayName(bool brief=false) const
Returns an english string representation of the day of the week.
bool operator==(const Date &rhs) const
Comparison operator.
Month month() const
Returns the month.
static int yearUpperLimit() noexcept
Returns the largest supported year value.
int monthday() const
Returns the day of the month.
Date & operator++()
Increments the date by one day.
std::string yyyy() const
Returns the year as a four-digit decimal string.
std::string dd() const
Returns the day of the month as a two-digit decimal string.
std::string str(Format format=Format::yyyy_mm_dd_slash) const
Returns a string representation of the date.
Weekday weekday() const
Returns the day of the week.
Date next() const
Returns the next date.
bool operator!=(const Date &rhs) const
Comparison operator.
static int yearLowerLimit() noexcept
Returns the smallest supported year value.
Date previous() const
Returns the previous date.
int year() const
Returns the year.
std::string mm() const
Returns the month as a two-digit decimal string.
static std::string fromInt(int i)
Converts int 'i' to a string.
Represents a unix-epoch time with microsecond resolution.
static SystemTime now()
Factory function for the current time.
BrokenDownTime local() const
Returns the locale-dependent local broken-down time.
BrokenDownTime utc() const
Returns the utc broken-down time.