Present  0.9
 All Classes Files Functions Variables Typedefs Friends Macros Pages
Date Struct Reference

Class or struct representing a calendar date. More...

Public Member Functions

int_year year () const
 Get the year of a Date. More...
 
int_month month () const
 Get the month of a Date (1 to 12, inclusive). More...
 
int_day day () const
 Get the day of month of a Date (1 to 31, inclusive). More...
 
int_day_of_year day_of_year () const
 Get the day of the year of a Date (1 to 366, inclusive). More...
 
PresentWeekYear week_of_year () const
 Get the week of the year of a Date (1 to 53, inclusive), and the year corresponding to that week. More...
 
int_day_of_week day_of_week () const
 Get the day of the week of a Date (1 to 7, inclusive, with 1 being Monday, 2 being Tuesday, ..., 6 being Saturday, and 7 being Sunday). More...
 
DayDelta difference (const Date &other) const
 Get the difference between two Date instances. More...
 
DayDelta absolute_difference (const Date &other) const
 Get the absolute difference between two Date instances. More...
 
Dateoperator+= (const DayDelta &delta)
 Add a DayDelta to a Date. More...
 
Dateoperator+= (const MonthDelta &delta)
 Add a MonthDelta to a Date. More...
 
Dateoperator-= (const DayDelta &delta)
 Subtract a DayDelta from a Date. More...
 
Dateoperator-= (const MonthDelta &delta)
 Subtract a MonthDelta from a Date. More...
 

Static Public Member Functions

static Date create (int_year year)
 Create a new Date based on a year. More...
 
static Date create (int_year year, int_month month)
 Create a new Date based on a year and a month. More...
 
static Date create (int_year year, int_month month, int_day day)
 Create a new Date based on a year, a month, and a day. More...
 
static Date from_year_day (int_year year, int_day_of_year day_of_year)
 Create a new Date based on a year and the day of that year. More...
 
static Date from_year_week_day (int_year year, int_week_of_year week_of_year, int_day_of_week day_of_week)
 Create a new Date based on a year, a week of that year, and a day of the week. More...
 
static short compare (const Date &lhs, const Date &rhs)
 Compare two Date instances. More...
 

Public Attributes

present_bool has_error
 This will be true if there were any errors when creating this Date. More...
 
struct {
   unsigned int   month_out_of_range: 1
 
   unsigned int   day_out_of_range: 1
 
   unsigned int   week_of_year_out_of_range: 1
 
   unsigned int   day_of_week_out_of_range: 1
 
errors
 If there were any errors when creating this Date, then one or more of these fields will be set. More...
 
struct PresentDateData data_
 

Friends

const Date operator+ (const Date &lhs, const DayDelta &rhs)
 
const Date operator+ (const DayDelta &lhs, const Date &rhs)
 
const Date operator+ (const Date &lhs, const MonthDelta &rhs)
 
const Date operator+ (const MonthDelta &lhs, const Date &rhs)
 
const Date operator- (const Date &lhs, const DayDelta &rhs)
 
const Date operator- (const Date &lhs, const MonthDelta &rhs)
 
bool operator== (const Date &lhs, const Date &rhs)
 Determine whether two Date instances are equal (lhs == rhs). More...
 
bool operator!= (const Date &lhs, const Date &rhs)
 
bool operator< (const Date &lhs, const Date &rhs)
 Determine whether a Date is earlier than another Date (lhs < rhs). More...
 
bool operator<= (const Date &lhs, const Date &rhs)
 Determine whether a Date is earlier than or the same as another Date (lhs <= rhs). More...
 
bool operator> (const Date &lhs, const Date &rhs)
 Determine whether a Date is later than another Date (lhs > rhs). More...
 
bool operator>= (const Date &lhs, const Date &rhs)
 Determine whether a Date is later than or the same as another Date (lhs >= rhs). More...
 

Detailed Description

Class or struct representing a calendar date.

This includes a year, a month, and a day. There is no time-of-day stored with the date, nor a time zone.

Member Function Documentation

static Date Date::create ( int_year  year)
static

Create a new Date based on a year.

The month and day will be set to January 1.

Parameters
yearThe year.
static Date Date::create ( int_year  year,
int_month  month 
)
static

Create a new Date based on a year and a month.

The day will be set to the first of the month.

If the month is out of range, the Date will have has_error and errors set.

Attention
Make sure to check for any errors by checking if the has_error field on the returned struct is true.

If has_error is true, then at least one of the fields in the errors struct will also be true.

See Also
Date::has_error
Date::errors
Parameters
yearThe year.
monthThe month of the year (1 to 12, inclusive).
static Date Date::create ( int_year  year,
int_month  month,
int_day  day 
)
static

Create a new Date based on a year, a month, and a day.

If the month or the day is out of range, the Date will have has_error and errors set.

Attention
Make sure to check for any errors by checking if the has_error field on the returned struct is true.

If has_error is true, then at least one of the fields in the errors struct will also be true.

See Also
Date::has_error
Date::errors
Parameters
yearThe year.
monthThe month of the year (1 to 12, inclusive).
dayThe day of the month (1 to either 28, 29, 30, or 31, inclusive, depending on the month).
static Date Date::from_year_day ( int_year  year,
int_day_of_year  day_of_year 
)
static

Create a new Date based on a year and the day of that year.

Parameters
yearThe year.
day_of_yearThe day of the year.
static Date Date::from_year_week_day ( int_year  year,
int_week_of_year  week_of_year,
int_day_of_week  day_of_week 
)
static

Create a new Date based on a year, a week of that year, and a day of the week.

Weeks of the year are determined in the same way that the ISO8601 standard defines week numbers. For more info, see: https://en.wikipedia.org/wiki/ISO_week_date

If the week of the year or the day of the week is out of range, the Date will have has_error and errors set.

Attention
Make sure to check for any errors by checking if the has_error field on the returned struct is true.

If has_error is true, then at least one of the fields in the errors struct will also be true.

See Also
Date::has_error
Date::errors
Parameters
yearThe year.
week_of_yearThe week of the year (1 to 52 or 53, inclusive, depending on the year).
day_of_weekThe day of the week (1 to 7, inclusive). See present/internal/types.h for constants for each day of the week.
int_year Date::year ( ) const

Get the year of a Date.

int_month Date::month ( ) const

Get the month of a Date (1 to 12, inclusive).

int_day Date::day ( ) const

Get the day of month of a Date (1 to 31, inclusive).

int_day_of_year Date::day_of_year ( ) const

Get the day of the year of a Date (1 to 366, inclusive).

PresentWeekYear Date::week_of_year ( ) const

Get the week of the year of a Date (1 to 53, inclusive), and the year corresponding to that week.

See Also
PresentWeekYear
int_day_of_week Date::day_of_week ( ) const

Get the day of the week of a Date (1 to 7, inclusive, with 1 being Monday, 2 being Tuesday, ..., 6 being Saturday, and 7 being Sunday).

DayDelta Date::difference ( const Date other) const

Get the difference between two Date instances.

DayDelta Date::absolute_difference ( const Date other) const

Get the absolute difference between two Date instances.

Date& Date::operator+= ( const DayDelta delta)

Add a DayDelta to a Date.

Date& Date::operator+= ( const MonthDelta delta)

Add a MonthDelta to a Date.

Date& Date::operator-= ( const DayDelta delta)

Subtract a DayDelta from a Date.

Date& Date::operator-= ( const MonthDelta delta)

Subtract a MonthDelta from a Date.

static short Date::compare ( const Date lhs,
const Date rhs 
)
static

Compare two Date instances.

  • If lhs < rhs, then a negative integer will be returned.
  • If lhs == rhs, then 0 will be returned.
  • If lhs > rhs, then a positive integer will be returned.

Friends And Related Function Documentation

const Date operator+ ( const Date lhs,
const DayDelta rhs 
)
friend
const Date operator+ ( const DayDelta lhs,
const Date rhs 
)
friend
const Date operator+ ( const Date lhs,
const MonthDelta rhs 
)
friend
const Date operator+ ( const MonthDelta lhs,
const Date rhs 
)
friend
const Date operator- ( const Date lhs,
const DayDelta rhs 
)
friend
const Date operator- ( const Date lhs,
const MonthDelta rhs 
)
friend
bool operator== ( const Date lhs,
const Date rhs 
)
friend

Determine whether two Date instances are equal (lhs == rhs).

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

Determine whether a Date is earlier than another Date (lhs < rhs).

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

Determine whether a Date is earlier than or the same as another Date (lhs <= rhs).

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

Determine whether a Date is later than another Date (lhs > rhs).

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

Determine whether a Date is later than or the same as another Date (lhs >= rhs).

Member Data Documentation

present_bool Date::has_error

This will be true if there were any errors when creating this Date.

For more details about the errors that occurred, see errors. For more details about the errors that occurred, see errors.

This field should be treated as read-only; DO NOT modify its contents!

unsigned int Date::month_out_of_range
unsigned int Date::day_out_of_range
unsigned int Date::week_of_year_out_of_range
unsigned int Date::day_of_week_out_of_range
struct { ... } Date::errors

If there were any errors when creating this Date, then one or more of these fields will be set.

To quickly check if any error occurred, see has_error. To quickly check if any error occurred, see has_error.

These fields should be treated as read-only; DO NOT modify their contents!

struct PresentDateData Date::data_

The documentation for this struct was generated from the following file: