wibble
1.1
|
This header provides functions to handle Gregorian calendar dates and times. More...
#include <string>
Go to the source code of this file.
Namespaces | |
wibble | |
wibble::grcal | |
wibble::grcal::date | |
Functions that work with int[6] datetime values. | |
wibble::grcal::dtime | |
Functions that work with int[3] time of day values. | |
Functions | |
void | wibble::grcal::date::today (int *dst) |
Fill in an int[6] with the UTC values for today (leaving the time of day elements to -1) More... | |
void | wibble::grcal::date::now (int *dst) |
Fill in an int[6] with the UTC values for now. More... | |
int | wibble::grcal::date::daysinmonth (int year, int month) |
Return the number of days in a month. More... | |
int | wibble::grcal::date::daysinyear (int year) |
Return the number of days in a year. More... | |
void | wibble::grcal::date::easter (int year, int *month, int *day) |
Compute the day of Easter. More... | |
void | wibble::grcal::date::lowerbound (const int *src, int *dst) |
Make a copy of the datetime, filling in missing values with the lowest possible value they can have. More... | |
void | wibble::grcal::date::lowerbound (int *val) |
Fill in the missing values of a datetime with the lowest possible value they can have. More... | |
void | wibble::grcal::date::upperbound (const int *src, int *dst) |
Make a copy of the datetime, filling in missing values with the highest possible value they can have. More... | |
void | wibble::grcal::date::upperbound (int *val) |
Fill in the missing values of a datetime with the highest possible value they can have. More... | |
void | wibble::grcal::date::normalise (int *res) |
Normalise a datetime, in place. More... | |
long long int | wibble::grcal::date::secondsfrom (int year, const int *val) |
Convert the given time in seconds elapsed since the beginning of the given year. More... | |
long long int | wibble::grcal::date::duration (const int *begin, const int *end) |
Give the duration in seconds of the interval between begin and end. More... | |
void | wibble::grcal::date::mergetime (const int *date, const int *time, int *dst) |
Make a copy of date, with the time part taken from time. More... | |
void | wibble::grcal::date::mergetime (int *date, const int *time) |
Replace the time part of date with the values from time. More... | |
void | wibble::grcal::date::totm (const int *src, struct tm *dst) |
Copy the values from an int[6] datetime into a struct tm. More... | |
void | wibble::grcal::date::fromtm (const struct tm &src, int *dst, int count=6) |
Copy the values from a struct tm to the first count values of the int[6] dst. More... | |
std::string | wibble::grcal::date::tostring (const int *val) |
Convert a datetime to a string. More... | |
void | wibble::grcal::dtime::lowerbound (const int *src, int *dst) |
Make a copy of the time, filling in missing values with the lowest possible value they can have. More... | |
void | wibble::grcal::dtime::lowerbound (int *val) |
Fill in the missing values of a time of day with the lowest possible value they can have. More... | |
int | wibble::grcal::dtime::lowerbound_sec (const int *src) |
Convert a time of day in second, filling the missing values with the lowest possible value they can have. More... | |
void | wibble::grcal::dtime::upperbound (const int *src, int *dst) |
Make a copy of the time, filling in missing values with the highest possible value they can have. More... | |
void | wibble::grcal::dtime::upperbound (int *val) |
Fill in the missing values of a time of day with the highest possible value they can have. More... | |
int | wibble::grcal::dtime::upperbound_sec (const int *src) |
Convert a time of day in second, filling the missing values with the highest possible value they can have. More... | |
int | wibble::grcal::dtime::duration (const int *begin, const int *end) |
Give the duration in seconds of the interval between the end of begin and the beginning of end. More... | |
std::string | wibble::grcal::dtime::tostring (const int *val) |
Format a time of day to a string. More... | |
std::string | wibble::grcal::dtime::tostring (int val) |
Format a time of day expressed in seconds to a string. More... | |
This header provides functions to handle Gregorian calendar dates and times.
The data type used through the module to represent a date is an int[6], containing: \l year \l month (starting from 1) \l day of month (starting from 1) \l hour \l minute \l second
The int[6] array does not need to be completely filled, and any value except for the year can be left missing, with the value of -1. However, if a value is set to -1, all the following values in the array must also be -1. For example, 'March 2008' can be represented as { 2008, 3, -1, -1, -1, -1 }, but something like { 2008, 3, -1, 12, -1, -1 } is not a valid date, as there can only be the value -1 after the first -1.
The date+time in the int[6] array is always stored in UTC: the module does not attempt to work with timezones or daylight saving.
The full range of the Gregorian calendar is accepted, so years like 1789 will work fine, although pay extra attention if you are comparing historical events of countries that adopted the Gregorian calendar in different times, like Russia or Greece.
Some functions work with the time of day only: those functions will work with int[3] parameters. The time of the day can also have missing values, with the same rules as the int[6] dates: this is midday: { 12, -1, -1 }, but this is not valid: { 12, -1, 30 }. However, in the case of int[3] times the hour can also be missing, so { -1, -1, -1 } is a valid time.
Some function represent the time as a single integer: that is intended to be the number of seconds after the start of the day. Therefore, midnight would be 0, and midday would be 43200 (12*3600).