3 .\" Copyright (c) 2009, The NetBSD Foundation.
4 .\" All Rights Reserved.
6 .\" This code is derived from software contributed to The NetBSD Foundation
9 .\" Redistribution and use in source and binary forms, with or without
10 .\" modification, are permitted provided that the following conditions
12 .\" 1. Redistributions of source code must retain the above copyright
13 .\" notice, this list of conditions and the following disclaimer.
14 .\" 2. Redistributions in binary form must reproduce the above copyright
15 .\" notice, this list of conditions and the following disclaimer in the
16 .\" documentation and/or other materials provided with the distribution.
18 .\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
19 .\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
20 .\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21 .\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
22 .\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23 .\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24 .\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 .\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26 .\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28 .\" POSSIBILITY OF SUCH DAMAGE.
36 .Nd convert user format date and time
45 .Vt extern int getdate_err ;
49 function converts a date or time character string pointed to by
55 The input string is parsed and interpreted using templates.
56 A text file containing templates is specified by the
59 This should contain the full path to the template file.
60 Lines in the template file represent acceptable date and/or time
61 conversion specifications.
62 These specifications are similar to those given for
64 The first line in the template file that matches the input string
65 is used to interpret and convert to internal time format.
66 .Ss Internal Format Conversion
67 The following rules apply to converting the input into the internal format.
68 .Bl -bullet -offset indent
70 If only the weekday is given, the conversion assumes today when the
71 weekday matches today or the first future matching weekday.
73 If only the month and no year is given, the conversion assumes the
74 current month when the month matches or the first future matching month.
75 The first day of the month is assumed if no day is given.
77 If only the year is given, the values of the
84 members of the returned
88 If the century is given, but the year within the century is not given,
89 the conversion assumes the current year.
91 If no hour, minute, and second are given, the conversion assumes
92 the current hour, minute, and second.
94 If no date is given, the conversion assumes today when the given hour
95 is greater than the current hour and tomorrow when the given hour is less.
99 is being scanned, then the broken-down time is based on the the
100 current time of the matched timezone and not the current runtime
101 environment timezone.
106 function returns a pointer to a static
108 structure containing the broken-down time.
109 Otherwise, a null pointer is returned and
111 is set to indicate the error.
115 can have the following values:
119 environment variable is null or undefined.
121 Cannot open the template file for reading.
123 Get file status failed for template file.
125 Template file is not a regular file.
127 Encountered an error while reading the template file.
129 Cannot allocate memory.
131 Input string does not match any line in the template file.
133 Input string is invalid
134 .Pq for example February 31
135 or could not be represented in a
139 .Bl -tag -width DATEMSK
141 The full path to the text file containing the templates
142 for acceptable date and/or time conversions.
145 .Bl -tag -width DATEMSK
146 .It Pa /usr/share/examples/getdate/datemsk.template
147 An example template file that could be specified via the
149 environment variable.
152 The following example shows the possible contents of a template file:
154 .Bd -literal -offset indent -compact
156 %A %B %d, %Y, %H:%M:%S
161 at %A the %dst of %B in %Y
162 run job at %I %p, %B %dnd
163 %A den %d. %B %Y %H.%M Uhr
166 The following are examples of valid input for the above template:
168 .Bd -literal -offset indent -compact
171 Firday September 18, 1987, 10:30:30
173 at monday the 1st of december in 1986
174 run job at 3 PM, december 2nd
177 The following examples show how local data and time specification can be
178 defined in the template.
180 .Bl -column -offset indent ".Sy Input String" ".Sy Line in Template"
181 .It Sy "Input String" Ta Sy "Line in Template"
182 .It Li 11/27/86 Ta Li \&%m/\&%d/\&%y
183 .It Li 27.11.86 Ta Li \&%d.\&%m/\&%y
184 .It Li 86-11-27 Ta Li \&%y-\&%m-\&%d
185 .It Li "Friday 12:00:00" Ta "\&%A \&%H:\&%M:\&%S"
188 The following examples illustrate the Internal Format Conversion rules
189 given that the current date is
190 .Li "Mon Sep 22 12:19:47 EDT 1986"
193 environment variable is set to the default C locale.
195 .Bl -column -offset indent ".Sy Input String" ".Sy Line in Template" ".Sy Date"
196 .It Sy Input String Ta Sy Line in Template Ta Sy Date
197 .It Li Mon Ta Li \&%a Ta Li "Mon Sep 22 12:19:47 EDT 1986"
198 .It Li Sun Ta Li \&%a Ta Li "Sun Sep 28 12:19:47 EDT 1986"
199 .It Li Fri Ta Li \&%a Ta Li "Sun Sep 26 12:19:47 EDT 1986"
200 .It Li September Ta Li \&%B Ta Li "Mon Sep 1 12:19:47 EDT 1986"
201 .It Li January Ta Li \&%B Ta Li "Thu Jan 1 12:19:47 EST 1987"
202 .It Li December Ta Li \&%B Ta Li "Mon Dec 1 12:19:47 EST 1987"
203 .It Li "Sep Mon" Ta Li "\&%b %a" Ta Li "Mon Sep 1 12:19:47 EDT 1986"
204 .It Li "Jan Fri" Ta Li "\&%b %a" Ta Li "Fri Jan 2 12:19:47 EDT 1987"
205 .It Li "Dec Mon" Ta Li "\&%b %a" Ta Li "Mon Dec 1 12:19:47 EDT 1986"
206 .It Li "Jan Wed 1989" Ta Li "\&%b \&%a \&%Y" Ta Li "Wed Jan 4 12:19:47 EST 1989"
207 .It Li "Fri 9" Ta Li "\&%a \&%H" Ta Li "Fri Sep 26 09:00:00 EDT 1986"
208 .It Li "Feb 10:30" Ta Li "\&%b \&%H:\&%S" Ta Li "Sun Feb 1 10:00:30 EST 1987"
209 .It Li 10:30 Ta Li "\&%H:\&%M" Ta Li "Tue Sep 23 10:30:00 EDT 1986"
210 .It Li 13:30 Ta Li "\&%H:\&%M" Ta Li "Tue Sep 22 13:30:00 EDT 1986"
232 interface is inherently unsafe for multi-threaded programs or libraries,
233 since it returns a pointer to a static variable and uses a global state