65 G_ASSERT( year >= yearLowerLimit() ) ;
66 G_ASSERT( year <= yearUpperLimit() ) ;
71 m_day = day_of_month ;
77 m_weekday_set = false ;
82 m_year = tm.tm_year + 1900 ;
83 m_month = tm.tm_mon + 1 ;
85 m_weekday_set = false ;
91 std::ostringstream ss ;
92 if( format == yyyy_mm_dd_slash )
94 ss << yyyy() <<
"/" << mm() <<
"/" << dd() ;
96 else if( format == yyyy_mm_dd )
98 ss << yyyy() << mm() << dd() ;
100 else if( format == mm_dd )
118 std::ostringstream ss ;
119 ss << std::setw(2) << std::setfill(
'0') << m_day ;
125 std::ostringstream ss ;
126 ss << std::setw(2) << std::setfill(
'0') << m_month ;
132 if( ! m_weekday_set )
135 tm.tm_year = m_year - 1900 ;
136 tm.tm_mon = m_month - 1 ;
147 const_cast<Date*
>(
this)->m_weekday_set =
true ;
148 const_cast<Date*
>(
this)->m_weekday =
Weekday(out.tm_wday) ;
155 if( weekday() == sunday )
return brief ?
"Sun" :
"Sunday" ;
156 if( weekday() == monday )
return brief ?
"Mon" :
"Monday" ;
157 if( weekday() == tuesday )
return brief ?
"Tue" :
"Tuesday" ;
158 if( weekday() == wednesday )
return brief ?
"Wed" :
"Wednesday" ;
159 if( weekday() == thursday )
return brief ?
"Thu" :
"Thursday" ;
160 if( weekday() == friday )
return brief ?
"Fri" :
"Friday" ;
161 if( weekday() == saturday )
return brief ?
"Sat" :
"Saturday" ;
167 return Month(m_month) ;
172 if( month() == january )
return brief ?
"Jan" :
"January" ;
173 if( month() == february )
return brief ?
"Feb" :
"February" ;
174 if( month() == march )
return brief ?
"Mar" :
"March" ;
175 if( month() == april )
return brief ?
"Apr" :
"April" ;
176 if( month() == may )
return brief ?
"May" :
"May" ;
177 if( month() == june )
return brief ?
"Jun" :
"June" ;
178 if( month() == july )
return brief ?
"Jul" :
"July" ;
179 if( month() == august )
return brief ?
"Aug" :
"August" ;
180 if( month() == september )
return brief ?
"Sep" :
"September" ;
181 if( month() == october )
return brief ?
"Oct" :
"October" ;
182 if( month() == november )
return brief ?
"Nov" :
"November" ;
183 if( month() == december )
return brief ?
"Dec" :
"December" ;
194 std::ostringstream ss ;
195 ss << std::setw(4) << std::setfill(
'0') << m_year ;
202 if( m_day == (lastDay(m_month,m_year)+1) )
214 if( m_weekday == saturday )
217 m_weekday =
Weekday(
int(m_weekday)+1) ;
236 m_day = lastDay( m_month , m_year ) ;
244 if( m_weekday == sunday )
245 m_weekday = saturday ;
247 m_weekday =
Weekday(
int(m_weekday)-1) ;
252 int G::Date::lastDay(
int month ,
int year )
265 else if( month == 2 )
267 end = isLeapYear(year) ? 29 : 28 ;
272 bool G::Date::isLeapYear(
int y )
274 return y >= 1800 && ( y % 400 == 0 || ( y % 100 != 0 && y % 4 == 0 ) ) ;
280 year() == other.
year() &&
281 month() == other.
month() &&
287 return !( other == *this ) ;
static BrokenDownTime utc(EpochTime epoch_time)
Converts from epoch time to UTC broken-down-time.
static EpochTime now()
Returns the current epoch time.
Month month() const
Returns the month.
A date (dd/mm/yyyy) class.
std::string monthName(bool brief=false) const
Returns the month as a string (in english).
static int yearLowerLimit()
Returns the smallest supported year value.
static BrokenDownTime local(EpochTime epoch_time)
Converts from epoch time to local broken-down-time.
bool operator!=(const Date &rhs) const
Comparison operator.
int monthday() const
Returns the day of the month.
int year() const
Returns the year.
bool operator==(const Date &rhs) const
Comparison operator.
An overload discriminator class for Date constructors.
std::string string(Format format=yyyy_mm_dd_slash) const
Returns a string representation of the date.
std::string dd() const
Returns the day of the month as a two-digit decimal string.
Date()
Default constructor for the current date in the UTC timezone.
std::string yyyy() const
Returns the year as a four-digit decimal string.
std::string weekdayName(bool brief=false) const
Returns an english string representation of the day of the week.
Date & operator--()
Decrements the date by one day.
Date & operator++()
Increments the date by one day.
Weekday weekday() const
Returns the day of the week.
static int yearUpperLimit()
Returns the largest supported year value.
struct std::tm BrokenDownTime
static EpochTime epochTime(const BrokenDownTime &broken_down_time)
Converts from UTC broken-down-time to epoch time.
std::string mm() const
Returns the month as a two-digit decimal string.