glibmm  2.62.0
About: glibmm is a set of C++ bindings for glib, including cross-platform APIs such as a std::string-like UTF8 string class, string utility methods, such as a text encoding converter API, file access, and threads.
  Fossies Dox: glibmm-2.62.0.tar.xz  ("inofficial" and yet experimental doxygen-generated source code documentation)  

Glib::Date Class Reference

Julian calendar date. More...

#include <date.h>

Public Types

enum  Month {
  BAD_MONTH, JANUARY, FEBRUARY, MARCH,
  APRIL, MAY, JUNE, JULY,
  AUGUST, SEPTEMBER, OCTOBER, NOVEMBER,
  DECEMBER
}
 
enum  Weekday {
  BAD_WEEKDAY, MONDAY, TUESDAY, WEDNESDAY,
  THURSDAY, FRIDAY, SATURDAY, SUNDAY
}
 
enum  DMY { DAY, MONTH, YEAR }
 
using Day = guint8
 
using Year = guint16
 

Public Member Functions

 Date ()
 Construct an undefined date. More...
 
 Date (Day day, Month month, Year year)
 Construct a date with the given day, month and year. More...
 
 Date (guint32 julian_day)
 Construct a date from a julian day. More...
 
 Date (const GDate &castitem)
 Construct a Glib::Date by copying the contents of a GDate. More...
 
 Date (const Date &other)
 Construct a Glib::Date from another. More...
 
Dateoperator= (const Date &other)
 Assign another date to this one. More...
 
GDate * gobj ()
 Provides access to the underlying C instance. More...
 
const GDate * gobj () const
 Provides access to the underlying C instance. More...
 
void clear ()
 Clear the date. More...
 
void set_parse (const Glib::ustring &str)
 Parses a user-inputted string str, and try to figure out what date it represents, taking the current locale into account. More...
 
G_GNUC_BEGIN_IGNORE_DEPRECATIONS G_GNUC_END_IGNORE_DEPRECATIONS void set_time (std::time_t timet)
 Sets the value of a date from a <type>std::time_t</type> value. More...
 
G_GNUC_BEGIN_IGNORE_DEPRECATIONS void set_time (const GTimeVal &timeval)
 Sets the value of a date from a GTimeVal value. More...
 
G_GNUC_END_IGNORE_DEPRECATIONS void set_time_current ()
 Set this Glib::Date to the current time. More...
 
void set_month (Month month)
 Sets the month of the year. More...
 
void set_day (Day day)
 Sets the day of the month. More...
 
void set_year (Year year)
 Sets the year. More...
 
void set_dmy (Day day, Month month, Year year)
 Sets the value of a day, month, and year. More...
 
void set_julian (guint32 julian_day)
 Sets the value of a GDate from a Julian day number. More...
 
Dateadd_days (int n_days)
 Add a number of days to a Date. More...
 
Datesubtract_days (int n_days)
 Subtract n_days to a Date. More...
 
Dateadd_months (int n_months)
 Add n_months to a Date. More...
 
Datesubtract_months (int n_months)
 Subtract n_months to a Date. More...
 
Dateadd_years (int n_years)
 Add n_days to a Date. More...
 
Datesubtract_years (int n_years)
 Subtract n_years to a Date. More...
 
int days_between (const Date &rhs) const
 Calculate days between two dates. More...
 
int compare (const Date &rhs) const
 Compare two dates. More...
 
Dateclamp (const Date &min_date, const Date &max_date)
 If date is prior to min_date, sets date equal to min_date. More...
 
Dateclamp_min (const Date &min_date)
 If date is prior to min_date, sets date equal to min_date. More...
 
Dateclamp_max (const Date &max_date)
 If date falls after max_date, sets date equal to max_date. More...
 
void order (Date &other)
 Checks if date is less than or equal to other date, and swap the values if this is not the case. More...
 
Weekday get_weekday () const
 Returns the day of the week for a Date. More...
 
Month get_month () const
 Returns the month of the year. More...
 
Year get_year () const
 Returns the year of a Date. More...
 
Day get_day () const
 Returns the day of the month. More...
 
guint32 get_julian () const
 Returns the Julian day or "serial number" of the Date. More...
 
unsigned int get_day_of_year () const
 Returns the day of the year, where Jan 1 is the first day of the year. More...
 
unsigned int get_monday_week_of_year () const
 Returns the week of the year, where weeks are understood to start on Monday. More...
 
unsigned int get_sunday_week_of_year () const
 Returns the week of the year during which this date falls, if weeks are understood to being on Sunday. More...
 
unsigned int get_iso8601_week_of_year () const
 Returns the week of the year, where weeks are interpreted according to ISO 8601. More...
 
bool is_first_of_month () const
 Returns true if the date is on the first of a month. More...
 
bool is_last_of_month () const
 Returns true if the date is the last day of the month. More...
 
Glib::ustring format_string (const Glib::ustring &format) const
 Convert date to string. More...
 
void to_struct_tm (struct tm &dest) const
 Fills in the date-related bits of a struct tm using the date value. More...
 
bool valid () const
 Returns true if the Date represents an existing day. More...
 

Static Public Member Functions

static guint8 get_days_in_month (Month month, Year year)
 Returns the number of days in a month, taking leap years into account. More...
 
static guint8 get_monday_weeks_in_year (Year year)
 Returns the number of weeks in the year, where weeks are taken to start on Monday. More...
 
static guint8 get_sunday_weeks_in_year (Year year)
 Returns the number of weeks in the year, where weeks are taken to start on Sunday. More...
 
static bool is_leap_year (Year year)
 Returns true if the year is a leap year. More...
 
static bool valid_day (Day day)
 Returns true if the day of the month is valid (a day is valid if it's between 1 and 31 inclusive). More...
 
static bool valid_month (Month month)
 Returns true if the month value is valid. More...
 
static bool valid_year (Year year)
 Returns true if the year is valid. More...
 
static bool valid_weekday (Weekday weekday)
 Returns true if the weekday is valid. More...
 
static bool valid_julian (guint32 julian_day)
 Returns true if the Julian day is valid. More...
 
static bool valid_dmy (Day day, Month month, Year year)
 Returns true if the day-month-year triplet forms a valid, existing day in the range of days Date understands (Year 1 or later, no more than a few thousand years in the future). More...
 

Static Public Attributes

static const Day BAD_DAY = 0
 
static const Year BAD_YEAR = 0
 
static const guint32 BAD_JULIAN = 0
 

Private Attributes

GDate gobject_
 

Related Functions

(Note that these are not member functions.)

bool operator== (const Date &lhs, const Date &rhs)
 
bool operator!= (const Date &lhs, const Date &rhs)
 
bool operator< (const Date &lhs, const Date &rhs)
 
bool operator> (const Date &lhs, const Date &rhs)
 
bool operator<= (const Date &lhs, const Date &rhs)
 
bool operator>= (const Date &lhs, const Date &rhs)
 

Detailed Description

Julian calendar date.

Definition at line 37 of file date.h.

Member Typedef Documentation

◆ Day

using Glib::Date::Day = guint8

Definition at line 40 of file date.h.

◆ Year

using Glib::Date::Year = guint16

Definition at line 41 of file date.h.

Constructor & Destructor Documentation

◆ Date() [1/5]

Glib::Date::Date ( )

Construct an undefined date.

Definition at line 38 of file date.cc.

References gobject_.

◆ Date() [2/5]

Glib::Date::Date ( Date::Day  day,
Date::Month  month,
Date::Year  year 
)

Construct a date with the given day, month and year.

Parameters
dayThe day.
monthThe month.
yearThe year.

Definition at line 43 of file date.cc.

References gobject_.

◆ Date() [3/5]

Glib::Date::Date ( guint32  julian_day)
explicit

Construct a date from a julian day.

Parameters
julian_dayThe julian day (guint32).

Definition at line 49 of file date.cc.

References gobject_.

◆ Date() [4/5]

Glib::Date::Date ( const GDate &  castitem)
explicit

Construct a Glib::Date by copying the contents of a GDate.

Parameters
castitemThe GDate.
Since @PACKAGE_NAME@ 2.18:

Definition at line 55 of file date.cc.

◆ Date() [5/5]

Glib::Date::Date ( const Date other)

Construct a Glib::Date from another.

Parameters
otherthe other Glib::Date.
Since @PACKAGE_NAME@ 2.18:

Definition at line 59 of file date.cc.

References get_julian(), and gobject_.

Member Function Documentation

◆ add_days()

Date & Glib::Date::add_days ( int  n_days)

Add a number of days to a Date.

This method returns a reference to the object itself, so you can write code such as:

somedate.add_days(2).add_months(3).add_years(17);
Parameters
n_daysDays to add.
Returns
Resulting Date

Definition at line 163 of file date.cc.

References gobject_.

◆ add_months()

Date & Glib::Date::add_months ( int  n_months)

Add n_months to a Date.

This method returns a reference to the object itself, so you can write code such as:

somedate.add_years(2).add_months(3).add_days(17);
Parameters
n_monthsMonths to add.
Returns
Resulting Date

Definition at line 183 of file date.cc.

References gobject_.

◆ add_years()

Date & Glib::Date::add_years ( int  n_years)

Add n_days to a Date.

This method returns a reference to the object itself, so you can write code such as:

somedate.add_years(2).add_months(3).add_days(17);
Parameters
n_yearsYears to add.
Returns
Resulting Date

Definition at line 203 of file date.cc.

References gobject_.

◆ clamp()

Date & Glib::Date::clamp ( const Date min_date,
const Date max_date 
)

If date is prior to min_date, sets date equal to min_date.

If date falls after max_date, sets date equal to max_date. All dates must be valid. See also clamp_min() and clamp_max(). This method returns a reference to the object itself.

Parameters
min_dateDate minimum value.
max_dateDate maximum value.
Returns
Date in interval.

Definition at line 235 of file date.cc.

References gobject_.

◆ clamp_max()

Date & Glib::Date::clamp_max ( const Date max_date)

If date falls after max_date, sets date equal to max_date.

See also clamp(), and clamp_min(). This method returns a reference to the object itself.

Parameters
max_dateDate maximum value.
Returns
Date in interval.

Definition at line 249 of file date.cc.

References gobject_.

◆ clamp_min()

Date & Glib::Date::clamp_min ( const Date min_date)

If date is prior to min_date, sets date equal to min_date.

See also clamp(), and clamp_max(). This method returns a reference to the object itself.

Parameters
min_dateDate minimum value.
Returns
Date in interval.

Definition at line 242 of file date.cc.

References gobject_.

◆ clear()

void Glib::Date::clear ( )

Clear the date.

The cleared dates will not represent an existing date, but will not contain garbage.

Definition at line 76 of file date.cc.

References gobject_.

◆ compare()

int Glib::Date::compare ( const Date rhs) const

Compare two dates.

Parameters
rhsDate to compare.
Returns
Result of comparition.

Definition at line 229 of file date.cc.

References gobject_.

Referenced by operator!=(), operator<(), operator<=(), operator==(), operator>(), and operator>=().

◆ days_between()

int Glib::Date::days_between ( const Date rhs) const

Calculate days between two dates.

Parameters
rhsDate.
Returns
Numbers of days.

Definition at line 223 of file date.cc.

References gobject_.

◆ format_string()

Glib::ustring Glib::Date::format_string ( const Glib::ustring format) const

Convert date to string.

Parameters
formatA format string as used by strftime(), in UTF-8 encoding. Only date formats are allowed, the result of time formats is undefined.
Returns
The formatted date string.
Exceptions
Glib::ConvertError

Definition at line 356 of file date.cc.

References gobject_, Glib::locale_from_utf8(), and Glib::locale_to_utf8().

◆ get_day()

Date::Day Glib::Date::get_day ( ) const

Returns the day of the month.

The date must be valid.

Returns
Day of the month..

Definition at line 280 of file date.cc.

References gobject_.

◆ get_day_of_year()

unsigned int Glib::Date::get_day_of_year ( ) const

Returns the day of the year, where Jan 1 is the first day of the year.

The date must be valid.

Returns
Julian day.

Definition at line 292 of file date.cc.

References gobject_.

◆ get_days_in_month()

guint8 Glib::Date::get_days_in_month ( Date::Month  month,
Date::Year  year 
)
static

Returns the number of days in a month, taking leap years into account.

Parameters
monthMonth.
yearYear.
Returns
Number of days in month during the year.

Definition at line 329 of file date.cc.

◆ get_iso8601_week_of_year()

unsigned int Glib::Date::get_iso8601_week_of_year ( ) const

Returns the week of the year, where weeks are interpreted according to ISO 8601.

The date must be valid.

Returns
ISO 8601 week number of the year.
Since @PACKAGE_NAME@ 2.22:

Definition at line 310 of file date.cc.

References gobject_.

◆ get_julian()

guint32 Glib::Date::get_julian ( ) const

Returns the Julian day or "serial number" of the Date.

The Julian day is simply the number of days since January 1, Year 1; i.e., January 1, Year 1 is Julian day 1; January 2, Year 1 is Julian day 2, etc. The date must be valid.

Returns
Julian day.

Definition at line 286 of file date.cc.

References gobject_.

Referenced by Date(), and operator=().

◆ get_monday_week_of_year()

unsigned int Glib::Date::get_monday_week_of_year ( ) const

Returns the week of the year, where weeks are understood to start on Monday.

If the date is before the first Monday of the year, return 0. The date must be valid.

Returns
Week of the year.

Definition at line 298 of file date.cc.

References gobject_.

◆ get_monday_weeks_in_year()

guint8 Glib::Date::get_monday_weeks_in_year ( Date::Year  year)
static

Returns the number of weeks in the year, where weeks are taken to start on Monday.

Will be 52 or 53. (Years always have 52 7-day periods, plus 1 or 2 extra days depending on whether it's a leap year. This function is basically telling you how many Mondays are in the year, i.e. there are 53 Mondays if one of the extra days happens to be a Monday.)

Parameters
yearYear to count weeks in.
Returns
Number of weeks.

Definition at line 336 of file date.cc.

◆ get_month()

Date::Month Glib::Date::get_month ( ) const

Returns the month of the year.

The date must be valid.

Returns
Month of the year as a Date::Month.

Definition at line 268 of file date.cc.

References gobject_.

◆ get_sunday_week_of_year()

unsigned int Glib::Date::get_sunday_week_of_year ( ) const

Returns the week of the year during which this date falls, if weeks are understood to being on Sunday.

Can return 0 if the day is before the first Sunday of the year. The date must be valid.

Returns
Week of the year.

Definition at line 304 of file date.cc.

References gobject_.

◆ get_sunday_weeks_in_year()

guint8 Glib::Date::get_sunday_weeks_in_year ( Date::Year  year)
static

Returns the number of weeks in the year, where weeks are taken to start on Sunday.

Will be 52 or 53. (Years always have 52 7-day periods, plus 1 or 2 extra days depending on whether it's a leap year. This function is basically telling you how many Sundays are in the year, i.e. there are 53 Sundays if one of the extra days happens to be a Sunday.)

Parameters
yearYear to count weeks in.
Returns
Number of weeks.

Definition at line 343 of file date.cc.

◆ get_weekday()

Date::Weekday Glib::Date::get_weekday ( ) const

Returns the day of the week for a Date.

The date must be valid.

Returns
Day of the week as a Date::Weekday.

Definition at line 262 of file date.cc.

References gobject_.

◆ get_year()

Date::Year Glib::Date::get_year ( ) const

Returns the year of a Date.

The date must be valid.

Returns
Year in which the date falls.

Definition at line 274 of file date.cc.

References gobject_.

◆ gobj() [1/2]

GDate* Glib::Date::gobj ( )
inline

Provides access to the underlying C instance.

Definition at line 228 of file date.h.

References gobject_.

◆ gobj() [2/2]

const GDate* Glib::Date::gobj ( ) const
inline

Provides access to the underlying C instance.

Definition at line 231 of file date.h.

References gobject_.

◆ is_first_of_month()

bool Glib::Date::is_first_of_month ( ) const

Returns true if the date is on the first of a month.

The date must be valid.

Returns
true if the date is the first of the month.

Definition at line 316 of file date.cc.

References gobject_.

◆ is_last_of_month()

bool Glib::Date::is_last_of_month ( ) const

Returns true if the date is the last day of the month.

The date must be valid.

Returns
true if the date is the last day of the month.

Definition at line 322 of file date.cc.

References gobject_.

◆ is_leap_year()

bool Glib::Date::is_leap_year ( Date::Year  year)
static

Returns true if the year is a leap year.

Parameters
yearYear to check.
Returns
true if the year is a leap year.

Definition at line 350 of file date.cc.

◆ operator=()

Date & Glib::Date::operator= ( const Date other)

Assign another date to this one.

For example:

...
Glib::Date my_date;
my_date = other_date;
Parameters
otherThe other Glib::Date.
Since @PACKAGE_NAME@ 2.18:

Definition at line 67 of file date.cc.

References get_julian(), and gobject_.

◆ order()

void Glib::Date::order ( Date other)

Checks if date is less than or equal to other date, and swap the values if this is not the case.

Parameters
otherDate ro compare.
Returns
Date.

Definition at line 256 of file date.cc.

References gobject_.

◆ set_day()

void Glib::Date::set_day ( Date::Day  day)

Sets the day of the month.

If the resulting day-month-year triplet is invalid, the date will be invalid.

Parameters
dayDay to set.

Definition at line 139 of file date.cc.

References gobject_.

◆ set_dmy()

void Glib::Date::set_dmy ( Date::Day  day,
Date::Month  month,
Date::Year  year 
)

Sets the value of a day, month, and year.

. If the resulting day-month-year triplet is invalid, the date will be invalid.

Parameters
dayDay to set.
monthMonth to set.
yearYear to set.

Definition at line 151 of file date.cc.

References gobject_.

◆ set_julian()

void Glib::Date::set_julian ( guint32  julian_day)

Sets the value of a GDate from a Julian day number.

Parameters
julian_dayJulian day to set.

Definition at line 157 of file date.cc.

References gobject_.

◆ set_month()

G_GNUC_END_IGNORE_DEPRECATIONS void Glib::Date::set_month ( Date::Month  month)

Sets the month of the year.

If the resulting day-month-year triplet is invalid, the date will be invalid.

Parameters
monthMonth to set.

Definition at line 133 of file date.cc.

References gobject_.

◆ set_parse()

void Glib::Date::set_parse ( const Glib::ustring str)

Parses a user-inputted string str, and try to figure out what date it represents, taking the current locale into account.

If the string is successfully parsed, the date will be valid after the call. Otherwise, it will be invalid. This function is not appropriate for file formats and the like; it isn't very precise, and its exact behavior varies with the locale. It's intended to be a heuristic routine that guesses what the user means by a given string (and it does work pretty well in that capacity).

Parameters
strString to parse.

Definition at line 82 of file date.cc.

References Glib::ustring::c_str(), and gobject_.

◆ set_time() [1/2]

G_GNUC_BEGIN_IGNORE_DEPRECATIONS void Glib::Date::set_time ( const GTimeVal &  timeval)

Sets the value of a date from a GTimeVal value.

Note that the tv_usec member is ignored, because Glib::Date can't make use of the additional precision.

Deprecated:
Use set_time(std::time_t timet) instead.
Parameters
timevalGTimeVal value to set

Since: 2.10

Definition at line 124 of file date.cc.

References gobject_.

◆ set_time() [2/2]

G_GNUC_BEGIN_IGNORE_DEPRECATIONS G_GNUC_END_IGNORE_DEPRECATIONS void Glib::Date::set_time ( std::time_t  timet)

Sets the value of a date from a <type>std::time_t</type> value.

Parameters
timetstd::time_t value to set
See also
set_time_current()

Since: 2.10

Definition at line 108 of file date.cc.

References gobject_.

◆ set_time_current()

void Glib::Date::set_time_current ( )

Set this Glib::Date to the current time.

Definition at line 114 of file date.cc.

References gobject_.

◆ set_year()

void Glib::Date::set_year ( Date::Year  year)

Sets the year.

If the resulting day-month-year triplet is invalid, the date will be invalid.

Parameters
yearYear to set.

Definition at line 145 of file date.cc.

References gobject_.

◆ subtract_days()

Date & Glib::Date::subtract_days ( int  n_days)

Subtract n_days to a Date.

This method returns a reference to the object itself, so you can write code such as:

somedate.subtract_days(2).subtract_months(3).subtract_years(17);
Parameters
n_daysDays to subtract.
Returns
Resulting Date

Definition at line 173 of file date.cc.

References gobject_.

◆ subtract_months()

Date & Glib::Date::subtract_months ( int  n_months)

Subtract n_months to a Date.

This method returns a reference to the object itself, so you can write code such as:

somedate.subtract_years(2).subtract_months(3).subtract_days(17);
Parameters
n_monthsMonths to subtract.
Returns
Resulting Date

Definition at line 193 of file date.cc.

References gobject_.

◆ subtract_years()

Date & Glib::Date::subtract_years ( int  n_years)

Subtract n_years to a Date.

This method returns a reference to the object itself, so you can write code such as:

somedate.subtract_years(2).subtract_months(3).subtract_days(17);
Parameters
n_yearsYears to subtract.
Returns
Resulting Date

Definition at line 213 of file date.cc.

References gobject_.

◆ to_struct_tm()

void Glib::Date::to_struct_tm ( struct tm &  dest) const

Fills in the date-related bits of a struct tm using the date value.

Initializes the non-date parts with something sane but meaningless.

Parameters
destStruct tm to fill.

Definition at line 388 of file date.cc.

References gobject_.

◆ valid()

bool Glib::Date::valid ( ) const

Returns true if the Date represents an existing day.

Returns
true if the date is valid.

Definition at line 394 of file date.cc.

References gobject_.

◆ valid_day()

bool Glib::Date::valid_day ( Date::Day  day)
static

Returns true if the day of the month is valid (a day is valid if it's between 1 and 31 inclusive).

Parameters
dayDay to check.
Returns
true if the day is valid.

Definition at line 401 of file date.cc.

◆ valid_dmy()

bool Glib::Date::valid_dmy ( Date::Day  day,
Date::Month  month,
Date::Year  year 
)
static

Returns true if the day-month-year triplet forms a valid, existing day in the range of days Date understands (Year 1 or later, no more than a few thousand years in the future).

Parameters
dayDay to check.
monthMonth to check.
yearYear to check.
Returns
true if the date is a valid one.

Definition at line 436 of file date.cc.

◆ valid_julian()

bool Glib::Date::valid_julian ( guint32  julian_day)
static

Returns true if the Julian day is valid.

Anything greater than zero is basically a valid Julian, though there is a 32-bit limit.

Parameters
julian_dayJulian day to check.
Returns
true if the Julian day is valid.

Definition at line 429 of file date.cc.

◆ valid_month()

bool Glib::Date::valid_month ( Date::Month  month)
static

Returns true if the month value is valid.

The 12 Date::Month enumeration values are the only valid months.

Parameters
monthMonth to check.
Returns
true if the month is valid.

Definition at line 408 of file date.cc.

◆ valid_weekday()

bool Glib::Date::valid_weekday ( Date::Weekday  weekday)
static

Returns true if the weekday is valid.

The 7 Date::Weekday enumeration values are the only valid.

Parameters
weekdayWeekday to check.
Returns
true if the weekday is valid.

Definition at line 422 of file date.cc.

◆ valid_year()

bool Glib::Date::valid_year ( Date::Year  year)
static

Returns true if the year is valid.

Any year greater than 0 is valid, though there is a 16-bit limit to what Date will understand.

Parameters
yearYear to check.
Returns
true if the year is valid.

Definition at line 415 of file date.cc.

Friends And Related Function Documentation

◆ operator!=()

bool operator!= ( const Date lhs,
const Date rhs 
)
related

Definition at line 599 of file date.h.

References compare().

◆ operator<()

bool operator< ( const Date lhs,
const Date rhs 
)
related

Definition at line 603 of file date.h.

References compare().

◆ operator<=()

bool operator<= ( const Date lhs,
const Date rhs 
)
related

Definition at line 611 of file date.h.

References compare().

◆ operator==()

bool operator== ( const Date lhs,
const Date rhs 
)
related

Definition at line 595 of file date.h.

References compare().

◆ operator>()

bool operator> ( const Date lhs,
const Date rhs 
)
related

Definition at line 607 of file date.h.

References compare().

◆ operator>=()

bool operator>= ( const Date lhs,
const Date rhs 
)
related

Definition at line 615 of file date.h.

References compare().

Member Data Documentation

◆ BAD_DAY

const Day Glib::Date::BAD_DAY = 0
static

Definition at line 180 of file date.h.

◆ BAD_JULIAN

const guint32 Glib::Date::BAD_JULIAN = 0
static

Definition at line 182 of file date.h.

◆ BAD_YEAR

const Year Glib::Date::BAD_YEAR = 0
static

Definition at line 181 of file date.h.

◆ gobject_


The documentation for this class was generated from the following files: