libiso8601  0.3.14
Enumerations | Functions
Parsing, printing and validation routines.

Enumerations

enum  iso8601_date_prec {
  iso8601_prec_year, iso8601_prec_month, iso8601_prec_day, iso8601_prec_ord,
  iso8601_prec_week, iso8601_prec_wday
}
 Date (day portion) precision.This enumeration will record how precisely the date was specified, as well as the format in use. It allows the library to determine the earliest and latest dates that could possibly be represented with the given input and also allows the output format to match the input format. More...
 
enum  iso8601_time_prec {
  iso8601_prec_none, iso8601_prec_hour, iso8601_prec_min, iso8601_prec_sec,
  iso8601_prec_hourfrac, iso8601_prec_minfrac, iso8601_prec_secfrac
}
 Time precision.This enumeration records how precisely the time was specified as well as its format. The fractional format will record whether it was the hour, minute or second that was specified with a fractional part, allowing a processed date/time to be presented to the user in the format it was originally encountered. More...
 

Functions

int iso8601_parse (const char *str, struct iso8601_date *earliest, struct iso8601_date *latest, struct iso8601_details *details)
 Parse ISO8601 date/time. More...
 
char * iso8601_print (char *str, int amt, const struct iso8601_date *date, const struct iso8601_details *details)
 Print ISO8601 date/time into string. More...
 
int iso8601_invalid (const struct iso8601_date *date)
 Validate ISO8601 date/time. More...
 

Detailed Description

These routines are used for parsing an ISO8601 date/time string into the internal structure used to represent them, and for validating such dates/times.

Enumeration Type Documentation

◆ iso8601_date_prec

Date (day portion) precision.This enumeration will record how precisely the date was specified, as well as the format in use. It allows the library to determine the earliest and latest dates that could possibly be represented with the given input and also allows the output format to match the input format.

Enumerator
iso8601_prec_year 

Only year specified.

iso8601_prec_month 

Year and month specified (calendar format).

iso8601_prec_day 

Year, month and day specified (calendar format).

iso8601_prec_ord 

Year and ordinal day specified (ordinal format).

iso8601_prec_week 

Year and week specified (week format).

iso8601_prec_wday 

Year, week and weekday specified (week format).

◆ iso8601_time_prec

Time precision.This enumeration records how precisely the time was specified as well as its format. The fractional format will record whether it was the hour, minute or second that was specified with a fractional part, allowing a processed date/time to be presented to the user in the format it was originally encountered.

Enumerator
iso8601_prec_none 

Don't display date.

iso8601_prec_hour 

Display integer part of hour.

iso8601_prec_min 

Display hour and integer part of minute.

iso8601_prec_sec 

Display hour, minute and integer part of second.

iso8601_prec_hourfrac 

Display hour and fractional part of hour.

iso8601_prec_minfrac 

Display hour, minute and fractional part of minute.

iso8601_prec_secfrac 

Display hour, minute, second and nanoseconds.

Function Documentation

◆ iso8601_parse()

int iso8601_parse ( const char *  str,
struct iso8601_date earliest,
struct iso8601_date latest,
struct iso8601_details details 
)

Parse ISO8601 date/time.

Parameters
strThe input string. Whitespace will be stripped.
[out]earliestThe earliest possible time the string could represent. May be 0.
[out]latestThe latest possible time the string could represent. May be 0.
[out]detailsStores details such as the precision to which the time/date were specified. May be 0.
Return values
-1on error.
0on success.

Parses a string containing the ISO8601 date/time. Deals with any format of date, optionally storing the details in details. The time may be partial, in which case this function returns the earliest and latest times that could possibly be represented by the string.

Note that this function will accept leap seconds (23:59:60) on days on which they occurred.

◆ iso8601_print()

char* iso8601_print ( char *  str,
int  amt,
const struct iso8601_date date,
const struct iso8601_details details 
)

Print ISO8601 date/time into string.

Parameters
strPointer to buffer into which result is written.
amtNumber of bytes in str.
dateDate to print.
detailsFormatting details (may be 0).
Returns
Pointer to buffer (str).

Formats and prints an ISO8601 date, optionally using the details in details. Will always return a null-terminated result, even if that means truncating the output to fit the buffer.

◆ iso8601_invalid()

int iso8601_invalid ( const struct iso8601_date date)

Validate ISO8601 date/time.

Parameters
dateThe date to validate.
Return values
-1if not valid.
0if valid.

Checks the details of date to ensure that they are sensible. This involves checking that sec is in the range 0 to 86399 (or 86400 if there is a leap second), and that nsec is in the range 0 to 999999999.