9.3 XSD lexical forms
AllApplicationManualNameSummaryHelp

  • Documentation
    • Reference manual
    • Packages
      • SWI-Prolog SGML/XML parser
        • Writing markup
          • XSD lexical forms
            • xsd_number_string/2
            • xsd_time_string/3
Availability::- use_module(library(sgml)).(can be autoloaded)
[det]xsd_time_string(?DateTime, ?Type, ?String)
Serialize and deserialize the XSD date and time formats. The converion is represented by the table below.

Prolog term Type XSD string
date(Y,M,D)xsd:dateYYYY-MM-DD
date_time(Y,M,D,H,Mi,S)xsd:dateTimeYYYY-MM-DDTHH-MM-SS
date_time(Y,M,D,H,Mi,S,0)xsd:dateTimeYYYY-MM-DDTHH-MM-SSZ
date_time(Y,M,D,H,Mi,S,TZ)xsd:dateTimeYYYY-MM-DDTHH-MM-SS[+-]HH:MM
time(H,M,S)xsd:timeHH:MM:SS
year_month(Y,M)xsd:gYearMonthYYYY-MM
month_day(M,D)xsd:gMonthDayMM-DD
Dxsd:gDayDD
Mxsd:gMonthMM
Yxsd:gYearYYYY

For the Prolog term all variables denote integers except for S, which represents seconds as either an integer or float. The TZ argument is the offset from UTC in seconds. The Type is written as xsd:name, but is in fact the full URI of the XSD data type, e.g., http://www.w3.org/2001/XMLSchema#date. In the XSD string notation, the letters YMDHS denote digits. The notation SS is either a two-digit integer or a decimal number with two digits before the floating point, e.g. 05.3 to denote 5.3 seconds.

For most conversions, Type may be specified unbound and is unified with the resulting type. For ambiguous conversions, Type must be specified or an instantiation_error is raised. When converting from Prolog to XSD serialization, D, M and Y are ambiguous. When convertion from XSD serialization to Prolog, only DD and MM are ambiguous. If Type and String are both given and String is a valid XSD date/time representation but not matching Type a syntax error with the shape syntax_error(Type) is raised. If DateTime and Type are both given and DateTime does not satisfy Type a domain_error of the shape domain_error(xsd_time(Type), DateTime) is raised.

The domain of numerical values is verified and a corresponding domain_error exception is raised if the domain is violated. There is no test for the existence of a date and thus "2016-02-31", although non-existing is accepted as valid.