OSDN Git Service

2011-08-05 Yannick Moy <moy@adacore.com>
[pf3gnuchains/gcc-fork.git] / gcc / ada / g-catiio.ads
1 ------------------------------------------------------------------------------
2 --                                                                          --
3 --                         GNAT RUN-TIME COMPONENTS                         --
4 --                                                                          --
5 --                G N A T . C A L E N D A R . T I M E _ I O                 --
6 --                                                                          --
7 --                                 S p e c                                  --
8 --                                                                          --
9 --                     Copyright (C) 1999-2010, AdaCore                     --
10 --                                                                          --
11 -- GNAT is free software;  you can  redistribute it  and/or modify it under --
12 -- terms of the  GNU General Public License as published  by the Free Soft- --
13 -- ware  Foundation;  either version 3,  or (at your option) any later ver- --
14 -- sion.  GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY;  without even the  implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE.                                     --
17 --                                                                          --
18 -- As a special exception under Section 7 of GPL version 3, you are granted --
19 -- additional permissions described in the GCC Runtime Library Exception,   --
20 -- version 3.1, as published by the Free Software Foundation.               --
21 --                                                                          --
22 -- You should have received a copy of the GNU General Public License and    --
23 -- a copy of the GCC Runtime Library Exception along with this program;     --
24 -- see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see    --
25 -- <http://www.gnu.org/licenses/>.                                          --
26 --                                                                          --
27 -- GNAT was originally developed  by the GNAT team at  New York University. --
28 -- Extensive contributions were provided by Ada Core Technologies Inc.      --
29 --                                                                          --
30 ------------------------------------------------------------------------------
31
32 --  This package augments standard Ada.Text_IO with facilities for input
33 --  and output of time values in standardized format.
34
35 package GNAT.Calendar.Time_IO is
36
37    Picture_Error : exception;
38    --  Exception raised for incorrect picture
39
40    type Picture_String is new String;
41    --  This is a string to describe date and time output format. The string is
42    --  a set of standard character and special tag that are replaced by the
43    --  corresponding values. It follows the GNU Date specification. Here are
44    --  the recognized directives :
45    --
46    --          %    a literal %
47    --          n    a newline
48    --          t    a horizontal tab
49    --
50    --          Time fields:
51    --
52    --          %H   hour (00..23)
53    --          %I   hour (01..12)
54    --          %k   hour ( 0..23)
55    --          %l   hour ( 1..12)
56    --          %M   minute (00..59)
57    --          %p   locale's AM or PM
58    --          %r   time, 12-hour (hh:mm:ss [AP]M)
59    --          %s   seconds  since 1970-01-01  00:00:00 UTC
60    --                (a nonstandard extension)
61    --          %S   second (00..59)
62    --          %T   time, 24-hour (hh:mm:ss)
63    --
64    --          Date fields:
65    --
66    --          %a   locale's abbreviated weekday name (Sun..Sat)
67    --          %A   locale's    full   weekday   name,    variable   length
68    --                  (Sunday..Saturday)
69    --          %b   locale's abbreviated month name (Jan..Dec)
70    --          %B   locale's    full    month    name,   variable    length
71    --                  (January..December)
72    --          %c   locale's date and time (Sat Nov 04 12:02:33 EST 1989)
73    --          %d   day of month (01..31)
74    --          %D   date (mm/dd/yy)
75    --          %h   same as %b
76    --          %j   day of year (001..366)
77    --          %m   month (01..12)
78    --          %U   week number  of year with  Sunday as first day  of week
79    --                  (00..53)
80    --          %w   day of week (0..6) with 0 corresponding to Sunday
81    --          %W   week number  of year with  Monday as first day  of week
82    --                  (00..53)
83    --          %x   locale's date representation (mm/dd/yy)
84    --          %y   last two digits of year (00..99)
85    --          %Y   year (1970...)
86    --
87    --          By default,  date pads numeric fields with zeroes.  GNU date
88    --          recognizes the following nonstandard numeric modifiers:
89    --
90    --          -    (hyphen) do not pad the field
91    --          _    (underscore) pad the field with spaces
92    --
93    --  Here are some GNAT extensions to the GNU Date specification:
94    --
95    --          %i   milliseconds (3 digits)
96    --          %e   microseconds (6 digits)
97    --          %o   nanoseconds  (9 digits)
98
99    ISO_Date : constant Picture_String;
100    --  This format follow the ISO 8601 standard. The format is "YYYY-MM-DD",
101    --  four digits year, month and day number separated by minus.
102
103    US_Date : constant Picture_String;
104    --  This format is the common US date format: "MM/DD/YY",
105    --  month and day number, two digits year separated by slashes.
106
107    European_Date : constant Picture_String;
108    --  This format is the common European date format: "DD/MM/YY",
109    --  day and month number, two digits year separated by slashes.
110
111    function Image
112      (Date    : Ada.Calendar.Time;
113       Picture : Picture_String) return String;
114    --  Return Date as a string with format Picture. Raise Picture_Error if
115    --  picture string is null or has an incorrect format.
116
117    function Value (Date : String) return Ada.Calendar.Time;
118    --  Parse the string Date and return its equivalent as a Time value. The
119    --  following time format is supported:
120    --
121    --     hh:mm:ss             - Date is the current date
122    --
123    --  The following formats are also supported. They all accept an optional
124    --  time with the format "hh:mm:ss". The time is separated from the date by
125    --  exactly one space character.
126    --
127    --  When the time is not specified, it is set to 00:00:00. The delimiter '*'
128    --  must be either '-' and '/' and both occurrences must use the same
129    --  character.
130    --
131    --  Trailing characters (in particular spaces) are not allowed
132    --
133    --     yyyy*mm*dd           - ISO format
134    --     yy*mm*dd             - Year is assumed to be 20yy
135    --     mm*dd*yyyy           - (US date format)
136    --     dd*mmm*yyyy          - month spelled out
137    --     yyyy*mmm*dd          - month spelled out
138    --     yyyymmdd             - Iso format, no separator
139    --     mmm dd, yyyy         - month spelled out
140    --     dd mmm yyyy          - month spelled out
141    --
142    --  Constraint_Error is raised if the input string is malformed (does not
143    --  conform to one of the above dates, or has an invalid time string), or
144    --  the resulting time is not valid.
145
146    procedure Put_Time (Date : Ada.Calendar.Time; Picture : Picture_String);
147    --  Put Date with format Picture. Raise Picture_Error if bad picture string
148
149 private
150    ISO_Date      : constant Picture_String := "%Y-%m-%d";
151    US_Date       : constant Picture_String := "%m/%d/%y";
152    European_Date : constant Picture_String := "%d/%m/%y";
153
154 end GNAT.Calendar.Time_IO;