wibble
1.1
|
Functions that work with int[6] datetime values. More...
Functions | |
int | daysinmonth (int year, int month) |
Return the number of days in a month. More... | |
int | daysinyear (int year) |
Return the number of days in a year. More... | |
void | easter (int year, int *month, int *day) |
Compute the day of Easter. More... | |
void | 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 | lowerbound (int *val) |
Fill in the missing values of a datetime with the lowest possible value they can have. More... | |
void | normalise (int *res) |
Normalise a datetime, in place. More... | |
void | 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 | upperbound (int *val) |
Fill in the missing values of a datetime with the highest possible value they can have. More... | |
long long int | secondsfrom (int year, const int *val) |
Convert the given time in seconds elapsed since the beginning of the given year. More... | |
long long int | duration (const int *begin, const int *end) |
Give the duration in seconds of the interval between begin and end. More... | |
void | mergetime (const int *date, const int *time, int *dst) |
Make a copy of date, with the time part taken from time. More... | |
void | mergetime (int *date, const int *time) |
Replace the time part of date with the values from time. More... | |
void | totm (const int *src, struct tm *dst) |
Copy the values from an int[6] datetime into a struct tm. More... | |
void | 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 | tostring (const int *val) |
Convert a datetime to a string. More... | |
void | today (int *dst) |
Fill in an int[6] with the UTC values for today (leaving the time of day elements to -1) More... | |
void | now (int *dst) |
Fill in an int[6] with the UTC values for now. More... | |
Functions that work with int[6] datetime values.
int wibble::grcal::date::daysinmonth | ( | int | year, |
int | month | ||
) |
Return the number of days in a month.
Referenced by secondsfrom().
int wibble::grcal::date::daysinyear | ( | int | year | ) |
Return the number of days in a year.
Referenced by secondsfrom().
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.
The result can be negative if end is an earlier date than begin.
References wibble::list::begin(), wibble::list::end(), wibble::grcal::dtime::lowerbound(), secondsfrom(), and wibble::grcal::dtime::upperbound().
void wibble::grcal::date::easter | ( | int | year, |
int * | month, | ||
int * | day | ||
) |
Compute the day of Easter.
The algorithm used is the Meeus/Jones/Butcher Gregorian algorithm described at http://en.wikipedia.org/wiki/Computus
void wibble::grcal::date::fromtm | ( | const struct tm & | src, |
int * | dst, | ||
int | count | ||
) |
Copy the values from a struct tm to the first count values of the int[6] dst.
References wibble::list::count().
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.
void wibble::grcal::date::lowerbound | ( | int * | val | ) |
Fill in the missing values of a datetime with the lowest possible value they can have.
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.
void wibble::grcal::date::mergetime | ( | int * | date, |
const int * | time | ||
) |
Replace the time part of date with the values from time.
void wibble::grcal::date::normalise | ( | int * | res | ) |
Normalise a datetime, in place.
This function takes in input a datetime with no missing values, but some values can be arbitrarily out of range. The datetime will be normalised so that all the elements will be within range, and it will still represent the same instant.
For example (remember that months and days start from 1, so a day of 0 means "last day of previous month"):
\l normalise({2007, 0, 1, 0, 0, 0}) gives {2006, 12, 1, 0, 0, 0} \l normalise({2007, -11, 1, 0, 0, 0}) gives {2006, 1, 1, 0, 0, 0} \l normalise({2007, 1, -364, 0, 0, 0}) gives {2006, 1, 1, 0, 0, 0} \l normalise({2007, 1, 366, 0, 0, 0}) gives {2008, 1, 1, 0, 0, 0} \l normalise({2009, 1, -364, 0, 0, 0}) gives {2008, 1, 2, 0, 0, 0}, because 2008 is a leap year \l normalise({2008, 1, 1, 0, 0, -3600}) gives {2007, 12, 31, 23, 0, 0}
Referenced by upperbound().
void wibble::grcal::date::now | ( | int * | dst | ) |
Fill in an int[6] with the UTC values for now.
Referenced by wibble::log::Timestamper::send(), and wibble::net::http::Request::send_date_header().
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.
Compute the number of seconds that elapsed from the beginning of the given year until the given datetime.
It is assumed that year <= t[0]
It is assumed that year <= val[0]: giving a year greather than val[0] will give unpredictable results.
References daysinmonth(), and daysinyear().
Referenced by duration().
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)
std::string wibble::grcal::date::tostring | ( | const int * | val | ) |
Convert a datetime to a string.
void wibble::grcal::date::totm | ( | const int * | src, |
struct tm * | dst | ||
) |
Copy the values from an int[6] datetime into a struct tm.
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.
References normalise().
void wibble::grcal::date::upperbound | ( | int * | val | ) |
Fill in the missing values of a datetime with the highest possible value they can have.
References normalise().