------------------------------------------------------------------------------ -- XML/Ada - An XML suite for Ada95 -- -- -- -- Copyright (C) 2005-2012, AdaCore -- -- -- -- This library is free software; you can redistribute it and/or modify it -- -- under terms of the GNU General Public License as published by the Free -- -- Software Foundation; either version 3, or (at your option) any later -- -- version. This library is distributed in the hope that it will be useful, -- -- but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHAN- -- -- TABILITY or FITNESS FOR A PARTICULAR PURPOSE. -- -- -- -- -- -- -- -- -- -- -- -- You should have received a copy of the GNU General Public License and -- -- a copy of the GCC Runtime Library Exception along with this program; -- -- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see -- -- . -- -- -- ------------------------------------------------------------------------------ -- This package provides handling for the various time-related types found -- in the XML schema standard. -- This includes durations, dates, times, and combination of those. -- -- We cannot use the standard Ada types to represent dates, since the range of -- dates supported by XML is much broader (any year should be manageable), -- which isn't supported directly by Ada. -- -- These types also handle timezones, which means that sometimes two dates -- might not be comparable if we do not know the timezone of one of them. The -- precise semantics of the comparison of dates is defined in the XML Schema -- standard part 3. with Sax.Symbols; use Sax.Symbols; with Sax.Utils; use Sax.Utils; package Schema.Date_Time is type duration_t is private; -- A duration, no timezone type date_time_t is private; -- A date and time, with timezone type date_t is private; -- A date, with timezone type time_t is private; -- A time, with timezone type gday_t is private; -- A day in a month, with timezone type gmonth_day_t is private; -- A month/day combination, with timezone type gmonth_t is private; -- A month, with timezone type gyear_t is private; -- A year, with timezone type gyear_month_t is private; -- A year/month combination, with timezone No_Time_T : constant time_t; No_Duration : constant duration_t; No_Date_Time : constant date_time_t; No_Date_T : constant date_t; No_GDay : constant gday_t; No_Month_Day : constant gmonth_day_t; No_Month : constant gmonth_t; No_Year : constant gyear_t; No_Year_Month : constant gyear_month_t; function Image (Date : date_time_t) return String; -- Return the string representation of Date, as defined in the XML -- schema standard, that is: -- yyyy-mm-ddThh:mm:ss.sss+tz:tz -- (year, month, day, hour, minutes, seconds, subseconds and timezone). -- The subsecond field's precision is given by the precision of the -- Duration type in Ada function Image (Duration : duration_t) return String; function Image (Time : time_t) return String; function Image (Date : date_t) return String; function Image (Day : gday_t) return String; function Image (Day : gmonth_day_t) return String; function Image (Month : gmonth_t) return String; function Image (Year : gyear_t) return String; function Image (Month : gyear_month_t) return String; -- Return the string representation of the argument procedure Value (Symbols : symbol_table; Ch : String; Val : out duration_t; Error : out symbol); -- Return the duration stored in Ch. It should contain a string of the -- type "PyyyyYmmM". subtype day_duration is Duration range 0.0 .. 86_400.0; function Sign (Duration : duration_t) return Integer; function Year (Duration : duration_t) return Natural; function Month (Duration : duration_t) return Natural; function Day (Duration : duration_t) return Natural; function Seconds (Duration : duration_t) return day_duration; -- Return the components of the duration. In general, you do not need to -- use this directly, and can instead use the "+" operator below to -- add it directly to a date. procedure Value (Symbols : symbol_table; Ch : String; Val : out date_time_t; Error : out symbol); -- Return the date stored in Ch. It should contain a string with the format -- yyyy-mm-ddThh:mm:ss.sss+tz:tz -- Any number of digits is supported for the date and the subseconds field function Year (Date : date_time_t) return Integer; function Month (Date : date_time_t) return Natural; function Day (Date : date_time_t) return Natural; -- Return the components of Date procedure Value (Symbols : symbol_table; Ch : String; Val : out time_t; Error : out symbol); procedure Value (Symbols : symbol_table; Ch : String; Val : out gday_t; Error : out symbol); procedure Value (Symbols : symbol_table; Ch : String; Val : out gmonth_day_t; Error : out symbol); procedure Value (Symbols : symbol_table; Ch : String; Val : out gyear_t; Error : out symbol); procedure Value (Symbols : symbol_table; Ch : String; Val : out gmonth_t; Error : out symbol); procedure Value (Symbols : symbol_table; Ch : String; Val : out gyear_month_t; Error : out symbol); procedure Value (Symbols : symbol_table; Ch : String; Val : out date_t; Error : out symbol); -- Return the date stored in Ch. The format of the string is specified in -- the XML Schema specifications function "+" (Date : date_time_t; Duration : duration_t) return date_time_t; -- Add duration to Date, according to the algorithm described in appendix -- E of the XML Schema standard function "<" (Time1, Time2 : date_time_t) return Boolean; function "<=" (Time1, Time2 : date_time_t) return Boolean; function "=" (Time1, Time2 : date_time_t) return Boolean; function ">" (Time1, Time2 : date_time_t) return Boolean; function ">=" (Time1, Time2 : date_time_t) return Boolean; -- Raises Not_Comparable if the two dates are not comparable according -- to the XML Schema standard. function "<" (Duration1, Duration2 : duration_t) return Boolean; function "<=" (Duration1, Duration2 : duration_t) return Boolean; function "=" (Duration1, Duration2 : duration_t) return Boolean; function ">" (Duration1, Duration2 : duration_t) return Boolean; function ">=" (Duration1, Duration2 : duration_t) return Boolean; -- Raises Not_Comparable if the two dates are not comparable according -- to the XML Schema standard. function "<" (Time1, Time2 : time_t) return Boolean; function "<=" (Time1, Time2 : time_t) return Boolean; function "=" (Time1, Time2 : time_t) return Boolean; function ">" (Time1, Time2 : time_t) return Boolean; function ">=" (Time1, Time2 : time_t) return Boolean; -- Raises Not_Comparable if the two times are not comparable according -- to the XML Schema standard. function "<" (Date1, Date2 : date_t) return Boolean; function "<=" (Date1, Date2 : date_t) return Boolean; function "=" (Date1, Date2 : date_t) return Boolean; function ">" (Date1, Date2 : date_t) return Boolean; function ">=" (Date1, Date2 : date_t) return Boolean; -- Raises Not_Comparable if the two times are not comparable according -- to the XML Schema standard. function "<" (Day1, Day2 : gday_t) return Boolean; function "<=" (Day1, Day2 : gday_t) return Boolean; function "=" (Day1, Day2 : gday_t) return Boolean; function ">" (Day1, Day2 : gday_t) return Boolean; function ">=" (Day1, Day2 : gday_t) return Boolean; -- Raises Not_Comparable if the two times are not comparable according -- to the XML Schema standard. function "<" (Day1, Day2 : gmonth_day_t) return Boolean; function "<=" (Day1, Day2 : gmonth_day_t) return Boolean; function "=" (Day1, Day2 : gmonth_day_t) return Boolean; function ">" (Day1, Day2 : gmonth_day_t) return Boolean; function ">=" (Day1, Day2 : gmonth_day_t) return Boolean; -- Raises Not_Comparable if the two times are not comparable according -- to the XML Schema standard. function "<" (Month1, Month2 : gmonth_t) return Boolean; function "<=" (Month1, Month2 : gmonth_t) return Boolean; function "=" (Month1, Month2 : gmonth_t) return Boolean; function ">" (Month1, Month2 : gmonth_t) return Boolean; function ">=" (Month1, Month2 : gmonth_t) return Boolean; -- Raises Not_Comparable if the two times are not comparable according -- to the XML Schema standard. function "<" (Month1, Month2 : gyear_month_t) return Boolean; function "<=" (Month1, Month2 : gyear_month_t) return Boolean; function "=" (Month1, Month2 : gyear_month_t) return Boolean; function ">" (Month1, Month2 : gyear_month_t) return Boolean; function ">=" (Month1, Month2 : gyear_month_t) return Boolean; -- Raises Not_Comparable if the two times are not comparable according -- to the XML Schema standard. function "<" (Year1, Year2 : gyear_t) return Boolean; function "<=" (Year1, Year2 : gyear_t) return Boolean; function "=" (Year1, Year2 : gyear_t) return Boolean; function ">" (Year1, Year2 : gyear_t) return Boolean; function ">=" (Year1, Year2 : gyear_t) return Boolean; -- Raises Not_Comparable if the two times are not comparable according -- to the XML Schema standard. Not_Comparable : exception; private subtype day_range is Duration range -86_400.0 .. 86_400.0; type timezone_t is new Integer; No_Timezone : constant timezone_t := timezone_t'last; -- A timezone indicator. This is an offset, in minutes, to UTC. type date_nz_t is record Year, Month, Day : Integer; end record; No_Date_NZ : constant date_nz_t := (0, 0, 0); -- A non-timezoned date. type gday_t is record Day : Integer; TZ : timezone_t; end record; No_Gday : constant gday_t := (0, No_Timezone); type gmonth_day_t is record Month, Day : Integer; TZ : timezone_t; end record; No_Month_Day : constant gmonth_day_t := (0, 0, No_Timezone); type gmonth_t is record Month : Integer; TZ : timezone_t; end record; No_Month : constant gmonth_t := (0, No_Timezone); type gyear_t is record Year : Integer; TZ : timezone_t; end record; No_Year : constant gyear_t := (0, No_Timezone); type gyear_month_t is record Year, Month : Integer; TZ : timezone_t; end record; No_Year_Month : constant gyear_month_t := (0, 0, No_Timezone); subtype time_nz_t is day_range; No_Time_NZ : constant time_nz_t := 0.0; -- A non-timezoned time type duration_t is record Sign : Integer; Year, Month, Day : Natural; Seconds : Duration; end record; No_Duration : constant duration_t := (1, 0, 0, 0, 0.0); -- A negative duration is representated by having all fields to a negative -- value. type date_t is record Date : date_nz_t; TZ : timezone_t; end record; No_Date_T : constant date_t := (No_Date_NZ, No_Timezone); -- A timezoned date. TZ is the timezone offset in minutes. It is set to -- Integer'Last if there is no timezone specified type time_t is record Time : time_nz_t; TZ : timezone_t; end record; No_Time_T : constant time_t := (No_Time_NZ, No_Timezone); -- A timezoned time type date_time_t is record Date : date_nz_t; Time : time_nz_t; TZ : timezone_t; end record; No_Date_Time : constant date_time_t := (No_Date_NZ, No_Time_NZ, No_Timezone); -- TZ is the timezone offset, in minutes. TZ is set to Integer'Last if -- there is no timezone specified end Schema.Date_Time;