libiso8601  0.3.14
Functions
Conversion and calculation routines.

Functions

int iso8601_isleap (int year)
 Is year a leap year? More...
 
void iso8601_to_cal (int *year, int *month, int *day, const struct iso8601_date *date)
 Convert date to calendar format. More...
 
int iso8601_from_cal (struct iso8601_date *date, int year, int month, int day)
 Convert date from calendar format. More...
 
void iso8601_to_ord (int *year, int *oday, const struct iso8601_date *date)
 Convert date to ordinal format. More...
 
int iso8601_from_ord (struct iso8601_date *date, int year, int oday)
 Convert date from ordinal format. More...
 
void iso8601_to_week (int *year, int *week, int *wday, const struct iso8601_date *date)
 Convert date to week format. More...
 
int iso8601_from_week (struct iso8601_date *date, int year, int week, int wday)
 Convert date from week format. More...
 
void iso8601_to_clocktime (int *hour, int *min, int *sec, const struct iso8601_date *date)
 Convert time to wall clock format. More...
 
int iso8601_from_clocktime (struct iso8601_date *date, int hour, int min, int sec)
 Convert time from wall clock format. More...
 

Detailed Description

This set of functions is useful for converting dates and times into formats understood by humans, and vice versa.

Function Documentation

◆ iso8601_isleap()

int iso8601_isleap ( int  year)

Is year a leap year?

Parameters
yearYear to examine.
Return values
0if not leap year.
non-0if leap year.

Returns non-0 if year is a leap year.

◆ iso8601_to_cal()

void iso8601_to_cal ( int *  year,
int *  month,
int *  day,
const struct iso8601_date date 
)

Convert date to calendar format.

Parameters
[out]yearCalendar year.
[out]monthCalendar month (1 to 12).
[out]dayCalendar day (starting from 1).
dateDate to convert.

◆ iso8601_from_cal()

int iso8601_from_cal ( struct iso8601_date date,
int  year,
int  month,
int  day 
)

Convert date from calendar format.

Parameters
[out]dateOutput date.
yearCalendar year.
monthCalendar month (1 to 12).
dayCalenday day (starting from 1).
Return values
0on success.
-1on error (and see errno).

Converts the date specified in year, month and day into date.

Note
Does not touch the sec or nsec time members of date. This means they will be unchanged after a call to this function. If this will lead to unexpected results, initialise the structure to 0 first.

◆ iso8601_to_ord()

void iso8601_to_ord ( int *  year,
int *  oday,
const struct iso8601_date date 
)

Convert date to ordinal format.

Parameters
[out]yearCalendar year.
[out]odayOrdinal day (from 1).
dateDate to convert.

◆ iso8601_from_ord()

int iso8601_from_ord ( struct iso8601_date date,
int  year,
int  oday 
)

Convert date from ordinal format.

Parameters
[out]dateOutput date.
yearCalendar year.
odayOrdinal day (from 1).
Return values
0on success.
-1on error (and see errno).

Converts the date specified into year and oday into date.

Note
Does not touch the sec or nsec time members of date. This means they will be unchanged after a call to this functoin. If this will lead to unexpected results, initialise the structure to 0 first.

◆ iso8601_to_week()

void iso8601_to_week ( int *  year,
int *  week,
int *  wday,
const struct iso8601_date date 
)

Convert date to week format.

Parameters
[out]yearCalendar year.
[out]weekISO week number (from 1).
[out]wdayISO week day number (1 = Monday, 7 = Sunday).
dateDate to convert.

◆ iso8601_from_week()

int iso8601_from_week ( struct iso8601_date date,
int  year,
int  week,
int  wday 
)

Convert date from week format.

Parameters
[out]dateOutput date.
yearCalendar year.
weekISO week number (from 1).
wdayISO week day number (1 = Monday, 7 = Sunday).
Return values
0on success.
-1on error (and see errno).

Converts the date specified into year, week and wday into date.

Note
Does not touch the sec or nsec time members of date. This means they will be unchanged after a call to this functoin. If this will lead to unexpected results, initialise the structure to 0 first.

◆ iso8601_to_clocktime()

void iso8601_to_clocktime ( int *  hour,
int *  min,
int *  sec,
const struct iso8601_date date 
)

Convert time to wall clock format.

Parameters
[out]hourOutput hour.
[out]minOutput minute.
[out]secOutput second.
dateDate/time to convert.

Converts the time stored in date into wall clock format, storing the result in hour, min and sec.

◆ iso8601_from_clocktime()

int iso8601_from_clocktime ( struct iso8601_date date,
int  hour,
int  min,
int  sec 
)

Convert time from wall clock format.

Parameters
[out]dateOutput time.
hourHour.
minMinute.
secSecond.
Return values
0on success.
-1on error (and see errno).

Converts the time as specified by hour, min and sec, storing the result in date.

Note
Does not touch the day (date) member of date. This means it will be unchanged after a call to this function. If this will lead to unexpected results, initialise the structure to 0 first.