## section-xsd section-xsd |

## Functions

rasqal_xsd_date * | rasqal_new_xsd_date ()
void | rasqal_free_xsd_date ()
char * | rasqal_xsd_date_to_counted_string ()
char * | rasqal_xsd_date_to_string ()
int | rasqal_xsd_date_equals ()
int | rasqal_xsd_date_compare ()
#define | RASQAL_XSD_DATETIME_NO_TZ
rasqal_xsd_datetime * | rasqal_new_xsd_datetime ()
rasqal_xsd_datetime * | rasqal_new_xsd_datetime_from_timeval ()
rasqal_xsd_datetime * | rasqal_new_xsd_datetime_from_unixtime ()
rasqal_xsd_datetime * | rasqal_new_xsd_datetime_from_xsd_date ()
void | rasqal_free_xsd_datetime ()
int | rasqal_xsd_datetime_compare ()
int | rasqal_xsd_datetime_compare2 ()
int | rasqal_xsd_datetime_equals ()
int | rasqal_xsd_datetime_equals2 ()
struct timeval * | rasqal_xsd_datetime_get_as_timeval ()
time_t | rasqal_xsd_datetime_get_as_unixtime ()
rasqal_xsd_decimal * | rasqal_xsd_datetime_get_seconds_as_decimal ()
char * | rasqal_xsd_datetime_get_timezone_as_counted_string ()
char * | rasqal_xsd_datetime_get_tz_as_counted_string ()
int | rasqal_xsd_datetime_set_from_timeval ()
int | rasqal_xsd_datetime_set_from_unixtime ()
char * | rasqal_xsd_datetime_to_counted_string ()
char * | rasqal_xsd_datetime_to_string ()
void | rasqal_free_xsd_decimal ()
rasqal_xsd_decimal * | rasqal_new_xsd_decimal ()
int | rasqal_xsd_decimal_abs ()
int | rasqal_xsd_decimal_add ()
char * | rasqal_xsd_decimal_as_counted_string ()
char * | rasqal_xsd_decimal_as_string ()
int | rasqal_xsd_decimal_ceil ()
int | rasqal_xsd_decimal_compare ()
int | rasqal_xsd_decimal_divide ()
int | rasqal_xsd_decimal_equals ()
int | rasqal_xsd_decimal_floor ()
double | rasqal_xsd_decimal_get_double ()
long | rasqal_xsd_decimal_get_long ()
int | rasqal_xsd_decimal_is_zero ()
int | rasqal_xsd_decimal_multiply ()
int | rasqal_xsd_decimal_negate ()
int | rasqal_xsd_decimal_print ()
int | rasqal_xsd_decimal_round ()
int | rasqal_xsd_decimal_set_double ()
int | rasqal_xsd_decimal_set_long ()
int | rasqal_xsd_decimal_set_string ()
int | rasqal_xsd_decimal_subtract ()

## Types and Values

| rasqal_xsd_date
| rasqal_xsd_datetime
typedef | rasqal_xsd_decimal

## Description

## Functions

### rasqal_new_xsd_date ()

    rasqal_xsd_date *
    rasqal_new_xsd_date (rasqal_world *world,
                         const char *date_string);

Constructor - make a new XSD date object from a string

#### Parameters

world | world object |
date_string | XSD date string |

#### Returns

new datetime or NULL on failure

### rasqal_free_xsd_date ()

    void
    rasqal_free_xsd_date (rasqal_xsd_date *d);

Destroy XSD date object.

#### Parameters

d | date object |

### rasqal_xsd_date_to_counted_string ()

    char *
    rasqal_xsd_date_to_counted_string (const rasqal_xsd_date *date,
                                       size_t *len_p);

Convert a rasqal_xsd_date struct to a xsd:date lexical form string.

Caller should `rasqal_free_memory()` the returned string.

See http://www.w3.org/TR/xmlschema-2/date-canonical-representation

#### Parameters

date | date struct |
len_p | output length (or NULL) |

#### Returns

lexical form string or NULL on failure.

### rasqal_xsd_date_to_string ()

    char *
    rasqal_xsd_date_to_string (const rasqal_xsd_date *d);

Convert a rasqal_xsd_date struct to a xsd:date lexical form string.

Caller should `rasqal_free_memory()` the returned string.

#### Parameters

d | date struct |

#### Returns

lexical form string or NULL on failure.

### rasqal_xsd_date_equals ()

    int
    rasqal_xsd_date_equals (const rasqal_xsd_date *d1,
                            const rasqal_xsd_date *d2,
                            int *incomparible_p);

Compare two XSD dates for equality.

#### Parameters

d1 | first XSD date |
d2 | second XSD date |
incomparible_p | address to store incomparable flag (or NULL) |

#### Returns

non-0 if equal.

### rasqal_xsd_date_compare ()

    int
    rasqal_xsd_date_compare (const rasqal_xsd_date *d1,
                             const rasqal_xsd_date *d2,
                             int *incomparible_p);

Compare two XSD dates

If the only one of the two dates have timezones, the results may be incomparible and that will return >0 and set the value of the int point to by `incomparible_p` to non-0

#### Parameters

d1 | first XSD date |
d2 | second XSD date |
incomparible_p | address to store incomparable flag (or NULL) |

#### Returns

<0 if `d1` is less than `d2` , 0 if equal, >0 otherwise

### RASQAL_XSD_DATETIME_NO_TZ

    #define RASQAL_XSD_DATETIME_NO_TZ (9999)

Sentinel XSD Decimal timezone value indicating no timezone is present.

### rasqal_new_xsd_datetime ()

    rasqal_xsd_datetime *
    rasqal_new_xsd_datetime (rasqal_world *world,
                             const char *datetime_string);

Constructor - make a new XSD datetime object from a string

#### Parameters

world | world object |
datetime_string | XSD Datetime string |

#### Returns

new datetime or NULL on failure

### rasqal_new_xsd_datetime_from_timeval ()

    rasqal_xsd_datetime *
    rasqal_new_xsd_datetime_from_timeval (rasqal_world *world,
                                          struct timeval *tv);

Constructor - make a new XSD datetime object from a timeval

#### Parameters

world | world object |
tv | pointer to struct timeval |

#### Returns

new datetime or NULL on failure

### rasqal_new_xsd_datetime_from_unixtime ()

    rasqal_xsd_datetime *
    rasqal_new_xsd_datetime_from_unixtime (rasqal_world *world,
                                           time_t secs);

Constructor - make a new XSD datetime object from unixtime seconds

#### Parameters

world | world object |
secs | unixtime |

#### Returns

new datetime or NULL on failure

### rasqal_new_xsd_datetime_from_xsd_date ()

    rasqal_xsd_datetime *
    rasqal_new_xsd_datetime_from_xsd_date (rasqal_world *world,
                                           rasqal_xsd_date *date);

Constructor - make a new XSD datetime object from an XSD date

#### Parameters

world | world object |
date | pointer to XSD date |

#### Returns

new datetime or NULL on failure

### rasqal_free_xsd_datetime ()

    void
    rasqal_free_xsd_datetime (rasqal_xsd_datetime *dt);

Destroy XSD datetime object.

#### Parameters

dt | datetime object |

### rasqal_xsd_datetime_compare ()

    int
    rasqal_xsd_datetime_compare (const rasqal_xsd_datetime *dt1,
                                 const rasqal_xsd_datetime *dt2);

`rasqal_xsd_datetime_compare` is deprecated and should not be used in newly-written code.

Compare two XSD dateTimes

`Deprecated` for `rasqal_xsd_datetime_compare2()` which can return the incomparible result.

#### Parameters

dt1 | first XSD dateTime |
dt2 | second XSD dateTime |

#### Returns

<0 if `dt1` is less than `dt2` , 0 if equal, >0 otherwise

### rasqal_xsd_datetime_compare2 ()

    int
    rasqal_xsd_datetime_compare2 (const rasqal_xsd_datetime *dt1,
                                  const rasqal_xsd_datetime *dt2,
                                  int *incomparible_p);

Compare two XSD dateTimes

If the only one of the two dateTimes have timezones, the results may be incomparible and that will return >0 and set the value of the int point to by `incomparible_p` to non-0

#### Parameters

dt1 | first XSD dateTime |
dt2 | second XSD dateTime |
incomparible_p | address to store incomparable flag (or NULL) |

#### Returns

<0 if `dt1` is less than `dt2` , 0 if equal, >0 otherwise

### rasqal_xsd_datetime_equals ()

    int
    rasqal_xsd_datetime_equals (const rasqal_xsd_datetime *dt1,
                                const rasqal_xsd_datetime *dt2);

`rasqal_xsd_datetime_equals` is deprecated and should not be used in newly-written code.

Compare two XSD dateTimes for equality.

`Deprecated` : for rasqal_xsd_datetime_equals2 that returns incomparibility.

#### Parameters

dt1 | first XSD dateTime |
dt2 | second XSD dateTime |

#### Returns

non-0 if equal.

### rasqal_xsd_datetime_equals2 ()

    int
    rasqal_xsd_datetime_equals2 (const rasqal_xsd_datetime *dt1,
                                 const rasqal_xsd_datetime *dt2,
                                 int *incomparible_p);

Compare two XSD dateTimes for equality.

#### Parameters

dt1 | first XSD dateTime |
dt2 | second XSD dateTime |
incomparible_p | address to store incomparable flag (or NULL) |

#### Returns

non-0 if equal.

### rasqal_xsd_datetime_get_as_timeval ()

    struct timeval *
    rasqal_xsd_datetime_get_as_timeval (rasqal_xsd_datetime *dt);

Get a datetime as struct timeval

The returned timeval must be freed by the caller such as using `rasqal_free_memory()`.

#### Parameters

dt | datetime |

#### Returns

pointer to a new timeval structure or NULL on failure

### rasqal_xsd_datetime_get_as_unixtime ()

    time_t
    rasqal_xsd_datetime_get_as_unixtime (rasqal_xsd_datetime *dt);

Get a datetime as unix seconds

#### Parameters

dt | datetime |

#### Returns

unix seconds or 0 if `dt` is NULL

### rasqal_xsd_datetime_get_seconds_as_decimal ()

    rasqal_xsd_decimal *
    rasqal_xsd_datetime_get_seconds_as_decimal
                                   (rasqal_world *world,
                                    rasqal_xsd_datetime *dt);

Get the seconds component of a dateTime as a decimal

#### Parameters

world | world object |
dt | XSD dateTime |

#### Returns

decimal object or NULL on failure

### rasqal_xsd_datetime_get_timezone_as_counted_string ()

    char *
    rasqal_xsd_datetime_get_timezone_as_counted_string
                                   (rasqal_xsd_datetime *dt,
                                    size_t *len_p);

Get the timezone of a datetime as a duration format string with optional length count

The returned string is owned by the caller and must be freed by `rasqal_free_memory()`.

#### Parameters

dt | datetime |
len_p | pointer to store returned string length |

#### Returns

pointer to a new string or NULL on failure

### rasqal_xsd_datetime_get_tz_as_counted_string ()

    char *
    rasqal_xsd_datetime_get_tz_as_counted_string
                                   (rasqal_xsd_datetime *dt,
                                    size_t *len_p);

Get the timezone of a datetime as a timezone string

The returned string is owned by the caller and must be freed by `rasqal_free_memory()`.

#### Parameters

dt | datetime |
len_p | pointer to store returned string length |

#### Returns

pointer to a new string or NULL on failure

### rasqal_xsd_datetime_set_from_timeval ()

    int
    rasqal_xsd_datetime_set_from_timeval (rasqal_xsd_datetime *dt,
                                          struct timeval *tv);

Set an XSD dateTime from a struct timeval pointer

#### Parameters

dt | datetime |
tv | timeval |

#### Returns

non-0 on failure

### rasqal_xsd_datetime_set_from_unixtime ()

    int
    rasqal_xsd_datetime_set_from_unixtime (rasqal_xsd_datetime *dt,
                                           time_t clock);

Set an XSD dateTime from unixtime seconds

#### Parameters

dt | date time |
clock | unix time in seconds |

#### Returns

non-0 on failure

### rasqal_xsd_datetime_to_counted_string ()

    char *
    rasqal_xsd_datetime_to_counted_string (const rasqal_xsd_datetime *dt,
                                           size_t *len_p);

Convert a rasqal_xsd_datetime struct to a xsd:dateTime lexical form counted string.

Caller should `rasqal_free_memory()` the returned string.

See http://www.w3.org/TR/xmlschema-2/dateTime-canonical-representation

#### Parameters

dt | datetime struct |
len_p | output length (or NULL) |

#### Returns

lexical form string or NULL on failure.

### rasqal_xsd_datetime_to_string ()

    char *
    rasqal_xsd_datetime_to_string (const rasqal_xsd_datetime *dt);

Convert a rasqal_xsd_datetime struct to a xsd:dateTime lexical form string.

Caller should `rasqal_free_memory()` the returned string.

#### Parameters

dt | datetime struct |

#### Returns

lexical form string or NULL on failure.

### rasqal_free_xsd_decimal ()

    void
    rasqal_free_xsd_decimal (rasqal_xsd_decimal *dec);

Destroy XSD Decimal object.

#### Parameters

dec | Decimal object |

### rasqal_new_xsd_decimal ()

    rasqal_xsd_decimal *
    rasqal_new_xsd_decimal (rasqal_world *world);

Create a new XSD Decimal object.

#### Parameters

world | rasqal world object |

#### Returns

new xsd:decimal object or NULL on failure.

### rasqal_xsd_decimal_abs ()

    int
    rasqal_xsd_decimal_abs (rasqal_xsd_decimal *result,
                            rasqal_xsd_decimal *a);

Return the absolute value of an XSD Decimal

#### Parameters

result | result variable |
a | argment decimal |

#### Returns

non-0 on failure

### rasqal_xsd_decimal_add ()

    int
    rasqal_xsd_decimal_add (rasqal_xsd_decimal *result,
                            rasqal_xsd_decimal *a,
                            rasqal_xsd_decimal *b);

Add two XSD Decimals and store in result XSD Decimal

#### Parameters

result | result variable |
a | argment decimal 1 |
b | argument decimal 2 |

#### Returns

non-0 on failure

### rasqal_xsd_decimal_as_counted_string ()

    char *
    rasqal_xsd_decimal_as_counted_string (rasqal_xsd_decimal *dec,
                                          size_t *len_p);

Get an XSD Decimal as a string lexical form with optional length.

The returned string is shared and owned by the `dec` object and must be copied. If `len_p` is not NULL, the length of the returned string is stored.

#### Parameters

dec | XSD Decimal |
len_p | pointer to length variable (or NULL) |

#### Returns

lexical form string or NULL on failure.

### rasqal_xsd_decimal_as_string ()

    char *
    rasqal_xsd_decimal_as_string (rasqal_xsd_decimal *dec);

Get an XSD Decimal as a string lexical form.

The returned string is shared and owned by the `dec` object and must be copied.

#### Parameters

dec | XSD Decimal |

#### Returns

lexical form string or NULL on failure.

### rasqal_xsd_decimal_ceil ()

    int
    rasqal_xsd_decimal_ceil (rasqal_xsd_decimal *result,
                             rasqal_xsd_decimal *a);

Return the number with no fractional part closes to argument for an XSD Decimal

#### Parameters

result | result variable |
a | argment decimal |

#### Returns

non-0 on failure

### rasqal_xsd_decimal_compare ()

    int
    rasqal_xsd_decimal_compare (rasqal_xsd_decimal *a,
                                rasqal_xsd_decimal *b);

Compare two XSD Decimals

#### Parameters

a | first XSD decimal |
b | second XSD decimal |

#### Returns

<0 if `a` is less than `b` , 0 if equal, >1 otherwise

### rasqal_xsd_decimal_divide ()

    int
    rasqal_xsd_decimal_divide (rasqal_xsd_decimal *result,
                               rasqal_xsd_decimal *a,
                               rasqal_xsd_decimal *b);

Divide two XSD Decimals and store in result XSD Decimal

If the divisor `b` is 0, failure is returned

#### Parameters

result | result variable |
a | argment decimal 1 |
b | argument decimal 2 |

#### Returns

non-0 on failure

### rasqal_xsd_decimal_equals ()

    int
    rasqal_xsd_decimal_equals (rasqal_xsd_decimal *a,
                               rasqal_xsd_decimal *b);

Compare two XSD Decimals for equality.

#### Parameters

a | first XSD Decimal |
b | second XSD Decimal |

#### Returns

non-0 if equal.

### rasqal_xsd_decimal_floor ()

    int
    rasqal_xsd_decimal_floor (rasqal_xsd_decimal *result,
                              rasqal_xsd_decimal *a);

Return the number with no fractional part closes to argument for an XSD Decimal

#### Parameters

result | result variable |
a | argment decimal |

#### Returns

non-0 on failure

### rasqal_xsd_decimal_get_double ()

    double
    rasqal_xsd_decimal_get_double (rasqal_xsd_decimal *dec);

Get an XSD Decimal as a double (may lose precision)

#### Parameters

dec | XSD Decimal |

#### Returns

double value.

### rasqal_xsd_decimal_get_long ()

    long
    rasqal_xsd_decimal_get_long (rasqal_xsd_decimal *dec,
                                 int *error_p);

Get an XSD Decimal as a long (may lose precision)

#### Parameters

dec | XSD Decimal |
error_p | pointer to error flag |

#### Returns

long value or 0 on failure and *error_p is non-0

### rasqal_xsd_decimal_is_zero ()

    int
    rasqal_xsd_decimal_is_zero (rasqal_xsd_decimal *d);

Test if an XSD decimal is zero.

#### Parameters

d | decimal |

#### Returns

non-0 if decimal is zero

### rasqal_xsd_decimal_multiply ()

    int
    rasqal_xsd_decimal_multiply (rasqal_xsd_decimal *result,
                                 rasqal_xsd_decimal *a,
                                 rasqal_xsd_decimal *b);

Multiply two XSD Decimals and store in result XSD Decimal

#### Parameters

result | result variable |
a | argment decimal 1 |
b | argument decimal 2 |

#### Returns

non-0 on failure

### rasqal_xsd_decimal_negate ()

    int
    rasqal_xsd_decimal_negate (rasqal_xsd_decimal *result,
                               rasqal_xsd_decimal *a);

Negate an XSD Decimal

#### Parameters

result | result variable |
a | argment decimal |

#### Returns

non-0 on failure

### rasqal_xsd_decimal_print ()

    int
    rasqal_xsd_decimal_print (rasqal_xsd_decimal *dec,
                              FILE *stream);

Print an XSD Decimal to a stream

#### Parameters

dec | XSD Decimal object |
stream | FILE* handle to print to |

#### Returns

non-0 on failure

### rasqal_xsd_decimal_round ()

    int
    rasqal_xsd_decimal_round (rasqal_xsd_decimal *result,
                              rasqal_xsd_decimal *a);

Return the number with no fractional part closes to argument for an XSD Decimal

#### Parameters

result | result variable |
a | argment decimal |

#### Returns

non-0 on failure

### rasqal_xsd_decimal_set_double ()

    int
    rasqal_xsd_decimal_set_double (rasqal_xsd_decimal *dec,
                                   double d);

Set an XSD Decimal value from a double.

#### Parameters

dec | XSD Decimal |
d | double |

#### Returns

non-0 on failure

### rasqal_xsd_decimal_set_long ()

    int
    rasqal_xsd_decimal_set_long (rasqal_xsd_decimal *dec,
                                 long l Param2);

Set an XSD Decimal value from a long.

#### Parameters

dec | XSD Decimal |
l | long |

#### Returns

non-0 on failure

### rasqal_xsd_decimal_set_string ()

    int
    rasqal_xsd_decimal_set_string (rasqal_xsd_decimal *dec,
                                   const char *string);

Set an XSD Decimal value from a string lexical form

#### Parameters

dec | XSD Decimal |
string | lexical form |

#### Returns

non-0 on failure

### rasqal_xsd_decimal_subtract ()

    int
    rasqal_xsd_decimal_subtract (rasqal_xsd_decimal *result,
                                 rasqal_xsd_decimal *a,
                                 rasqal_xsd_decimal *b);

Subtract two XSD Decimals and store in result XSD Decimal

#### Parameters

result | result variable |
a | argment decimal 1 |
b | argument decimal 2 |

#### Returns

non-0 on failure

## Types and Values

### rasqal_xsd_date

    typedef struct {
      signed int year;
      /* the following fields are integer values not characters */
      unsigned char month;
      unsigned char day;
      signed short timezone_minutes;
      time_t time_on_timeline;
      char have_tz;
    } rasqal_xsd_date;

XML schema date datatype (xsd:date)

Examples of timezone fields: "2010-01-02" : timezone_minutes RASQAL_XSD_DATETIME_NO_TZ, have_tz 'N' "2010-01-02Z" : timezone_minutes 0, have_tz 'Z' "2010-01-02+00:00" : timezone_minutes 0, have_tz 'Y' "2010-01-02-01:00" : timezone_minutes -60, have_tz 'Y'

#### Members

signed int `year`; | year |
unsigned char `month`; | month 1-12 |
unsigned char `day`; | 1-31 |
signed short `timezone_minutes`; | minutes +/- against UTC or RASQAL_XSD_DATETIME_NO_TZ if there is no timezone in the dateTime. |
time_t `time_on_timeline`; | time on timeline of first instant of date in timezone |
char `have_tz`; | timezone flag: 'Z' if Zulu, 'Y' if has other timezone offset in `timezone_minutes` , 'N' if there is no timezone |

### rasqal_xsd_datetime

    typedef struct {
      signed int year;
      unsigned char month;
      unsigned char day;
      /* the following fields are integer values not characters */
      signed char hour;
      signed char minute;
      signed char second;
      signed int microseconds;
      signed short timezone_minutes;
      time_t time_on_timeline;
      char have_tz;
    } rasqal_xsd_datetime;

XML Schema dateTime datatype (xsd:dateTime)

Signed types are required for normalization process where a value can be negative temporarily.

Examples of timezone fields: "2010-01-02T01:02:03" : timezone_minutes RASQAL_XSD_DATETIME_NO_TZ, have_tz 'N' "2010-01-02T01:02:03Z" : timezone_minutes 0, have_tz 'Z' "2010-01-02T01:02:03+00:00" : timezone_minutes 0, have_tz 'Y' "2010-01-02T01:02:03-01:00" : timezone_minutes -60, have_tz 'Y'

#### Members

signed int `year`; | year |
unsigned char `month`; | month 1-12 |
unsigned char `day`; | 1-31 |
signed char `hour`; | hour 0-23 |
signed char `minute`; | minute 0-59 |
signed char `second`; | second 0-60 (yes 60 is allowed for leap seconds) |
signed int `microseconds`; | microseconds |
signed short `timezone_minutes`; | minutes +/- against UTC or RASQAL_XSD_DATETIME_NO_TZ if there is no timezone in the dateTime. |
time_t `time_on_timeline`; | time on timeline |
char `have_tz`; | timezone flag: 'Z' if Zulu, 'Y' if has other timezone offset in `timezone_minutes` , 'N' if there is no timezone |

### rasqal_xsd_decimal

    typedef struct rasqal_xsd_decimal_s rasqal_xsd_decimal;

Rasqal XSD Decimal class.