wibble 1.1
Functions
wibble::grcal::date Namespace Reference

Functions that work with int[6] datetime values. More...

Functions

int daysinmonth (int year, int month)
 Return the number of days in a month.
 
int daysinyear (int year)
 Return the number of days in a year.
 
void easter (int year, int *month, int *day)
 Compute the day of Easter.
 
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.
 
void lowerbound (int *val)
 Fill in the missing values of a datetime with the lowest possible value they can have.
 
void normalise (int *res)
 Normalise a datetime, in place.
 
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.
 
void upperbound (int *val)
 Fill in the missing values of a datetime with the highest possible value they can have.
 
long long int secondsfrom (int year, const int *val)
 Convert the given time in seconds elapsed since the beginning of the given year.
 
long long int duration (const int *begin, const int *end)
 Give the duration in seconds of the interval between begin and end.
 
void mergetime (const int *date, const int *time, int *dst)
 Make a copy of date, with the time part taken from time.
 
void mergetime (int *date, const int *time)
 Replace the time part of date with the values from time.
 
void totm (const int *src, struct tm *dst)
 Copy the values from an int[6] datetime into a struct tm.
 
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.
 
std::string tostring (const int *val)
 Convert a datetime to a string.
 
void today (int *dst)
 Fill in an int[6] with the UTC values for today (leaving the time of day elements to -1)
 
void now (int *dst)
 Fill in an int[6] with the UTC values for now.
 

Detailed Description

Functions that work with int[6] datetime values.

Function Documentation

◆ daysinmonth()

int wibble::grcal::date::daysinmonth ( int  year,
int  month 
)

Return the number of days in a month.

Referenced by normalise(), and secondsfrom().

◆ daysinyear()

int wibble::grcal::date::daysinyear ( int  year)

Return the number of days in a year.

Referenced by secondsfrom().

◆ duration()

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 lowerbound(), secondsfrom(), and upperbound().

◆ easter()

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

◆ fromtm()

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.

◆ lowerbound() [1/2]

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.

Referenced by duration().

◆ lowerbound() [2/2]

void wibble::grcal::date::lowerbound ( int val)

Fill in the missing values of a datetime with the lowest possible value they can have.

◆ mergetime() [1/2]

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.

Note
time is an int[3] time value;

◆ mergetime() [2/2]

void wibble::grcal::date::mergetime ( int date,
const int time 
)

Replace the time part of date with the values from time.

Note
time is an int[3] time value;

◆ normalise()

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}

References daysinmonth().

Referenced by upperbound(), and upperbound().

◆ now()

void wibble::grcal::date::now ( int dst)

Fill in an int[6] with the UTC values for now.

◆ secondsfrom()

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

◆ today()

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)

◆ tostring()

std::string wibble::grcal::date::tostring ( const int val)

Convert a datetime to a string.

◆ totm()

void wibble::grcal::date::totm ( const int src,
struct tm dst 
)

Copy the values from an int[6] datetime into a struct tm.

◆ upperbound() [1/2]

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

Referenced by duration().

◆ upperbound() [2/2]

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