Present  0.9
 All Classes Files Functions Variables Typedefs Friends Macros Pages
date.h File Reference

Go to the source code of this file.

Classes

struct  PresentWeekYear
 Struct containing a year and a week of the year. More...
 
struct  Date
 Class or struct representing a calendar date. More...
 

Macros

#define Date_create(...)
 Create a new Date from either a year (1 argument), a year and a month (2 arguments), or a year/month/day (3 arguments). More...
 
#define Date_ptr_create(result,...)
 Create a new Date from either a year (2 arguments), a year and a month (3 arguments), or a year/month/day (4 arguments). More...
 

Functions

struct Date Date_from_year (int_year year)
 Create a new Date based on a year. More...
 
void Date_ptr_from_year (struct Date *const result, int_year year)
 Create a new Date based on a year. More...
 
struct Date Date_from_year_month (int_year year, int_month month)
 Create a new Date based on a year and a month. More...
 
void Date_ptr_from_year_month (struct Date *const result, int_year year, int_month month)
 Create a new Date based on a year and a month. More...
 
struct Date Date_from_year_month_day (int_year year, int_month month, int_day day)
 Create a new Date based on a year, a month, and a day. More...
 
void Date_ptr_from_year_month_day (struct Date *const result, int_year year, int_month month, int_day day)
 Create a new Date based on a year, a month, and a day. More...
 
struct Date 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...
 
void Date_ptr_from_year_day (struct Date *const result, 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...
 
struct Date 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...
 
void Date_ptr_from_year_week_day (struct Date *const result, 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...
 
int_year Date_year (const struct Date *const self)
 Get the year of a Date. More...
 
int_month Date_month (const struct Date *const self)
 Get the month of a Date (1 to 12, inclusive). More...
 
int_day Date_day (const struct Date *const self)
 Get the day of month of a Date (1 to 31, inclusive). More...
 
int_day_of_year Date_day_of_year (const struct Date *const self)
 Get the day of the year of a Date (1 to 366, inclusive). More...
 
struct PresentWeekYear Date_week_of_year (const struct Date *const self)
 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 Date_day_of_week (const struct Date *const self)
 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...
 
struct DayDelta Date_difference (const struct Date *const self, const struct Date *const other)
 Get the difference between two Date instances. More...
 
struct DayDelta Date_absolute_difference (const struct Date *const self, const struct Date *const other)
 Get the absolute difference between two Date instances. More...
 
void Date_add_DayDelta (struct Date *const self, const struct DayDelta *const delta)
 Add a DayDelta to a Date. More...
 
void Date_add_MonthDelta (struct Date *const self, const struct MonthDelta *const delta)
 Add a MonthDelta to a Date. More...
 
void Date_subtract_DayDelta (struct Date *const self, const struct DayDelta *const delta)
 Subtract a DayDelta from a Date. More...
 
void Date_subtract_MonthDelta (struct Date *const self, const struct MonthDelta *const delta)
 Subtract a MonthDelta from a Date. More...
 
short Date_compare (const struct Date *const lhs, const struct Date *const rhs)
 Compare two Date instances. More...
 
present_bool Date_equal (const struct Date *const lhs, const struct Date *const rhs)
 Determine whether two Date instances are equal (lhs == rhs). More...
 
present_bool Date_less_than (const struct Date *const lhs, const struct Date *const rhs)
 Determine whether a Date is earlier than another Date (lhs < rhs). More...
 
present_bool Date_less_than_or_equal (const struct Date *const lhs, const struct Date *const rhs)
 Determine whether a Date is earlier than or the same as another Date (lhs <= rhs). More...
 
present_bool Date_greater_than (const struct Date *const lhs, const struct Date *const rhs)
 Determine whether a Date is later than another Date (lhs > rhs). More...
 
present_bool Date_greater_than_or_equal (const struct Date *const lhs, const struct Date *const rhs)
 Determine whether a Date is later than or the same as another Date (lhs >= rhs). More...
 

Macro Definition Documentation

#define Date_create (   ...)
Value:
PRESENT_OVERLOAD_MAX_3(__VA_ARGS__, \
dummy)(__VA_ARGS__)
struct Date Date_from_year_month(int_year year, int_month month)
Create a new Date based on a year and a month.
struct Date Date_from_year_month_day(int_year year, int_month month, int_day day)
Create a new Date based on a year, a month, and a day.
struct Date Date_from_year(int_year year)
Create a new Date based on a year.

Create a new Date from either a year (1 argument), a year and a month (2 arguments), or a year/month/day (3 arguments).

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
Date_from_year
Date_from_year_month
Date_from_year_month_day
#define Date_ptr_create (   result,
  ... 
)
Value:
PRESENT_OVERLOAD_MAX_3(__VA_ARGS__, \
dummy)(result, __VA_ARGS__)
void Date_ptr_from_year_month(struct Date *const result, int_year year, int_month month)
Create a new Date based on a year and a month.
void Date_ptr_from_year_month_day(struct Date *const result, int_year year, int_month month, int_day day)
Create a new Date based on a year, a month, and a day.
void Date_ptr_from_year(struct Date *const result, int_year year)
Create a new Date based on a year.

Create a new Date from either a year (2 arguments), a year and a month (3 arguments), or a year/month/day (4 arguments).

The first argumen is a pointer to a struct Date for the result.

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
Date_ptr_from_year
Date_ptr_from_year_month
Date_ptr_from_year_month_day

Function Documentation

struct Date Date_from_year ( int_year  year)

Create a new Date based on a year.

The month and day will be set to January 1.

Parameters
yearThe year.
void Date_ptr_from_year ( struct Date *const  result,
int_year  year 
)

Create a new Date based on a year.

The month and day will be set to January 1.

Parameters
yearThe year.
[out]resultA pointer to a struct Date for the result.
struct Date Date_from_year_month ( int_year  year,
int_month  month 
)

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).
void Date_ptr_from_year_month ( struct Date *const  result,
int_year  year,
int_month  month 
)

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).
[out]resultA pointer to a struct Date for the result.
struct Date Date_from_year_month_day ( int_year  year,
int_month  month,
int_day  day 
)

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).
void Date_ptr_from_year_month_day ( struct Date *const  result,
int_year  year,
int_month  month,
int_day  day 
)

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).
[out]resultA pointer to a struct Date for the result.
struct Date 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.

Parameters
yearThe year.
day_of_yearThe day of the year.
void Date_ptr_from_year_day ( struct Date *const  result,
int_year  year,
int_day_of_year  day_of_year 
)

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

Parameters
yearThe year.
day_of_yearThe day of the year.
[out]resultA pointer to a struct Date for the result.
struct Date 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.

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.
void Date_ptr_from_year_week_day ( struct Date *const  result,
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.

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.
[out]resultA pointer to a struct Date for the result.
int_year Date_year ( const struct Date *const  self)

Get the year of a Date.

int_month Date_month ( const struct Date *const  self)

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

int_day Date_day ( const struct Date *const  self)

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

int_day_of_year Date_day_of_year ( const struct Date *const  self)

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

struct PresentWeekYear Date_week_of_year ( const struct Date *const  self)

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 struct Date *const  self)

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).

struct DayDelta Date_difference ( const struct Date *const  self,
const struct Date *const  other 
)

Get the difference between two Date instances.

struct DayDelta Date_absolute_difference ( const struct Date *const  self,
const struct Date *const  other 
)

Get the absolute difference between two Date instances.

void Date_add_DayDelta ( struct Date *const  self,
const struct DayDelta *const  delta 
)

Add a DayDelta to a Date.

void Date_add_MonthDelta ( struct Date *const  self,
const struct MonthDelta *const  delta 
)

Add a MonthDelta to a Date.

void Date_subtract_DayDelta ( struct Date *const  self,
const struct DayDelta *const  delta 
)

Subtract a DayDelta from a Date.

void Date_subtract_MonthDelta ( struct Date *const  self,
const struct MonthDelta *const  delta 
)

Subtract a MonthDelta from a Date.

short Date_compare ( const struct Date *const  lhs,
const struct Date *const  rhs 
)

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.
present_bool Date_equal ( const struct Date *const  lhs,
const struct Date *const  rhs 
)

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

present_bool Date_less_than ( const struct Date *const  lhs,
const struct Date *const  rhs 
)

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

present_bool Date_less_than_or_equal ( const struct Date *const  lhs,
const struct Date *const  rhs 
)

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

present_bool Date_greater_than ( const struct Date *const  lhs,
const struct Date *const  rhs 
)

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

present_bool Date_greater_than_or_equal ( const struct Date *const  lhs,
const struct Date *const  rhs 
)

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