7 .Nd convert user format date and time
10 .Vt extern int getdate_err ;
12 .Fn getdate "const char *string"
16 function converts user-definable date and/or
17 time specifications pointed to by
24 structure is defined in the
28 User-supplied templates are used to parse and interpret the
30 The templates are text files created by the
31 user and identified via the environment variable
33 Each line in the template represents an acceptable date
34 and/or time specification using conversion specifications
35 similar to those used by
39 Dates before 1902 and after 2037 are illegal.
41 in the template that matches the input specification is used
42 for interpretation and conversion into the internal time
45 .Ss "Conversion Specifications"
46 The following conversion specifications are supported:
47 .Bl -tag -width "xxxx"
51 Locale's abbreviated weekday name.
53 Locale's full weekday name.
55 Locale's abbreviated month name.
57 Locale's full month name.
59 Locale's appropriate date and time representation.
61 Century number (the year divided by 100 and truncated
62 to an integer as a decimal number [1,99]); single
63 digits are preceded by 0.
65 without the %y specifier, this format specifier will
66 assume the current year offset in whichever century is
67 specified. The only valid years are between 1902-2037.
69 day of month [01,31]; leading zero is permitted but
76 Locale's abbreviated month name.
78 Hour (24-hour clock) [0,23]; leading zero is permitted
81 Hour (12-hour clock) [1,12]; leading zero is permitted
84 Day number of the year [1,366]; leading zeros are permitted but not required.
86 Month number [1,12]; leading zero is permitted but not
89 Minute [0,59]; leading zero is permitted but not
94 Locale's equivalent of either a.m. or p.m.
96 Appropriate time representation in the 12-hour clock
101 Seconds [0,61]; leading zero is permitted but not
102 required. The range of values is [00,61] rather than
103 [00,59] to allow for the occasional leap second and
104 even more occasional double leap second.
110 Week number of the year as a decimal number [0,53],
111 with Sunday as the first day of the week; leading zero
112 is permitted but not required.
114 Weekday as a decimal number [0,6], with 0 representing
117 Week number of the year as a decimal number [0,53],
118 with Monday as the first day of the week; leading zero
119 is permitted but not required.
121 Locale's appropriate date representation.
123 Locale's appropriate time representation.
125 Year within century. When a century is not otherwise
126 specified, values in the range 69-99 refer to years in
127 the twentieth century (1969 to 1999 inclusive); values
128 in the range 00-68 refer to years in the twenty-first
129 century (2000 to 2068 inclusive).
131 Year, including the century (for example, 1993).
133 Time zone name or no characters if no time zone
136 .Ss "Modified Conversion Specifications"
137 Some conversion specifications can be modified by the E and
138 O modifier characters to indicate that an alternative format
139 or specification should be used rather than the one normally
140 used by the unmodified specification.
142 format or specification does not exist in the current
143 locale, the behavior be as if the unmodified conversion
144 specification were used.
145 .Bl -tag -width "xxxx"
147 Locale's alternative appropriate date and time
150 Name of the base year (period) in the locale's alternative representation.
152 Locale's alternative date representation.
154 Locale's alternative time representation.
156 Offset from %EC (year only) in the locale's alternative representation.
158 Full alternative year representation.
160 Day of the month using the locale's alternative
161 numeric symbols; leading zeros are permitted but not
166 Hour (24-hour clock) using the locale's alternative
169 Hour (12-hour clock) using the locale's alternative
172 Month using the locale's alternative numeric symbols.
174 Minutes using the locale's alternative numeric symbols.
176 Seconds using the locale's alternative numeric symbols.
178 Week number of the year (Sunday as the first day of
179 the week) using the locale's alternative numeric symbols.
181 Number of the weekday (Sunday=0) using the locale's
182 alternative numeric symbols.
184 Week number of the year (Monday as the first day of
185 the week) using the locale's alternative numeric symbols.
187 Year (offset from %C) in the locale's alternative
188 representation and using the locale's alternative
191 .Ss "Internal Format Conversion"
192 The following rules are applied for converting the input
193 specification into the internal format:
194 .Bl -bullet -offset indent
196 If only the weekday is given, today is assumed if the
197 given day is equal to the current day and next week if
200 If only the month is given, the current month is
201 assumed if the given month is equal to the current
202 month and next year if it is less and no year is
204 (The first day of month is assumed if no day is
207 If only the year is given, the values of the tm_mon,
208 tm_mday, tm_yday, tm_wday, and tm_isdst members of the
209 returned tm structure are not specified.
211 If the century is given, but the year within the century is not given,
212 the current year within the century
215 If no hour, minute, and second are given, the current
216 hour, minute, and second are assumed.
218 If no date is given, today is assumed if the given
219 hour is greater than the current hour and tomorrow is
220 assumed if it is less.
222 .Ss "General Specifications"
223 A conversion specification that is an ordinary character is
224 executed by scanning the next character from the buffer.
225 If the character scanned from the buffer differs from the one
226 comprising the conversion specification, the specification
227 fails, and the differing and subsequent characters remain
230 A series of conversion specifications composed of
233 white space characters, or any combination is executed by
234 scanning up to the first character that is not white space
235 (which remains unscanned), or until no more characters can
238 Any other conversion specification is executed by scanning
239 characters until a character matching the next conversion
240 specification is scanned, or until no more characters can be
242 These characters, except the one matching the next
243 conversion specification, are then compared to the locale
244 values associated with the conversion specifier.
245 If a match is found, values for the appropriate
248 are set to values corresponding to the locale information.
249 If no match is found,
251 fails and no more characters are scanned.
253 The month names, weekday names, era names, and alternative
254 numeric symbols can consist of any combination of upper and
256 The user can request that the input
257 date or time specification be in a specific language by setting the
264 returns a pointer to a
266 structure; otherwise, it returns
268 and sets the global variable
270 to indicate the error.
273 alter the contents of
276 The following is a complete list of the
278 settings and their meanings:
279 .Bl -tag -width "xxx"
281 The DATEMSK environment variable is null or undefined.
283 The template file cannot be opened for reading.
285 Failed to get file status information.
287 The template file is not a regular file.
289 An error is encountered while reading the template
294 function failed (not enough memory is
297 There is no line in the template that matches the
300 The input specification is invalid (for example,
306 function makes explicit use of macros
311 Example 1: Examples of the
315 The following example shows the possible contents of a template:
318 %A %B %d %Y, %H:%M:%S
323 at %A the %dst of %B in %Y
324 run job at %I %p,%B %dnd
325 %A den %d. %B %Y %H.%M Uhr
328 The following are examples of valid input specifications for
331 getdate("10/1/87 4 PM")
333 getdate("Friday September 19 1987, 10:30:30")
334 getdate("24,9,1986 10:30")
335 getdate("at monday the 1st of december in 1986")
336 getdate("run job at 3 PM, december 2nd")
341 environment variable is set to de (German), the
344 getdate("freitag den 10. oktober 1986 10.30 Uhr")
347 Local time and date specification are also supported.
348 The following examples show how local date and time specification
349 can be defined in the template.
356 Invocation Line in Template
357 getdate("11/27/86") %m/%d/%y
358 getdate("27.11.86") %d.%m.%y
359 getdate("86-11-27") %y-%m-%d
360 getdate("Friday 12:00:00") %A %H:%M:%S
364 The following examples illustrate the Internal Format
366 Assume that the current date is
367 .Li Mon Sep 22 12:19:47 EDT 1986
370 environment variable is not set.
377 Input Template Line Date
378 Mon %a Mon Sep 22 12:19:48 EDT 1986
379 Sun %a Sun Sep 28 12:19:49 EDT 1986
380 Fri %a Fri Sep 26 12:19:49 EDT 1986
381 September %B Mon Sep 1 12:19:49 EDT 1986
382 January %B Thu Jan 1 12:19:49 EST 1987
383 December %B Mon Dec 1 12:19:49 EDT 1986
384 Sep Mon %b %a Mon Sep 1 12:19:50 EDT 1986
385 Jan Fri %b %a Fri Jan 2 12:19:50 EST 1987
386 Dec Mon %b %a Mon Dec 1 12:19:50 EST 1986
387 Jan Wed 1989 %b %a %Y Wed Jan 4 12:19:51 EST 1989
388 Fri 9 %a %H Fri Sep 26 09:00:00 EDT 1986
389 Feb 10:30 %b %H:%S Sun Feb 1 10:00:30 EST 1987
390 10:30 %H:%M Tue Sep 23 10:30:00 EDT 1986
391 13:30 %H:%M Mon Sep 22 13:30:00 EDT 1986