1 .\" $NetBSD: getdate.3,v 1.2 2011/04/14 05:50:49 jruoho Exp $
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
53 structure described in
56 The input string is parsed and interpreted using templates.
57 A text file containing templates is specified by the
60 This should contain the full path to the template file.
61 Lines in the template file represent acceptable date and/or time
62 conversion specifications.
63 These specifications are similar to those given for
65 The first line in the template file that matches the input string
66 is used to interpret and convert to internal time format.
67 .Ss Internal Format Conversion
68 The following rules apply to converting the input into the internal format.
69 .Bl -bullet -offset indent
71 If only the weekday is given, the conversion assumes today when the
72 weekday matches today or the first future matching weekday.
74 If only the month and no year is given, the conversion assumes the
75 current month when the month matches or the first future matching month.
76 The first day of the month is assumed if no day is given.
78 If only the year is given, the values of the
85 members of the returned
89 If the century is given, but the year within the century is not given,
90 the conversion assumes the current year.
92 If no hour, minute, and second are given, the conversion assumes
93 the current hour, minute, and second.
95 If no date is given, the conversion assumes today when the given hour
96 is greater than the current hour and tomorrow when the given hour is less.
100 is being scanned, then the broken-down time is based on the the
101 current time of the matched timezone and not the current runtime
102 environment timezone.
107 function returns a pointer to a static
109 structure containing the broken-down time.
110 Otherwise, a null pointer is returned and
112 is set to indicate the error.
116 can have the following values:
120 environment variable is null or undefined.
122 Cannot open the template file for reading.
124 Get file status failed for template file.
126 Template file is not a regular file.
128 Encountered an error while reading the template file.
130 Cannot allocate memory.
132 Input string does not match any line in the template file.
134 Input string is invalid
135 .Pq for example February 31
136 or could not be represented in a
140 .Bl -tag -width DATEMSK
142 The full path to the text file containing the templates
143 for acceptable date and/or time conversions.
146 .Bl -tag -width DATEMSK
147 .It Pa /usr/share/examples/getdate/datemsk.template
148 An example template file that could be specified via the
150 environment variable.
153 The following example shows the possible contents of a template file:
155 .Bd -literal -offset indent -compact
157 %A %B %d, %Y, %H:%M:%S
162 at %A the %dst of %B in %Y
163 run job at %I %p, %B %dnd
164 %A den %d. %B %Y %H.%M Uhr
167 The following are examples of valid input for the above template:
169 .Bd -literal -offset indent -compact
172 Firday September 18, 1987, 10:30:30
174 at monday the 1st of december in 1986
175 run job at 3 PM, december 2nd
178 The following examples show how local data and time specification can be
179 defined in the template.
181 .Bl -column -offset indent ".Sy Input String" ".Sy Line in Template"
182 .It Sy "Input String" Ta Sy "Line in Template"
183 .It Li 11/27/86 Ta Li \&%m/\&%d/\&%y
184 .It Li 27.11.86 Ta Li \&%d.\&%m/\&%y
185 .It Li 86-11-27 Ta Li \&%y-\&%m-\&%d
186 .It Li "Friday 12:00:00" Ta "\&%A \&%H:\&%M:\&%S"
189 The following examples illustrate the Internal Format Conversion rules
190 given that the current date is
191 .Li "Mon Sep 22 12:19:47 EDT 1986"
194 environment variable is set to the default C locale.
196 .Bl -column -offset indent ".Sy Input String" ".Sy Line in Template" ".Sy Date"
197 .It Sy Input String Ta Sy Line in Template Ta Sy Date
198 .It Li Mon Ta Li \&%a Ta Li "Mon Sep 22 12:19:47 EDT 1986"
199 .It Li Sun Ta Li \&%a Ta Li "Sun Sep 28 12:19:47 EDT 1986"
200 .It Li Fri Ta Li \&%a Ta Li "Sun Sep 26 12:19:47 EDT 1986"
201 .It Li September Ta Li \&%B Ta Li "Mon Sep 1 12:19:47 EDT 1986"
202 .It Li January Ta Li \&%B Ta Li "Thu Jan 1 12:19:47 EST 1987"
203 .It Li December Ta Li \&%B Ta Li "Mon Dec 1 12:19:47 EST 1987"
204 .It Li "Sep Mon" Ta Li "\&%b %a" Ta Li "Mon Sep 1 12:19:47 EDT 1986"
205 .It Li "Jan Fri" Ta Li "\&%b %a" Ta Li "Fri Jan 2 12:19:47 EDT 1987"
206 .It Li "Dec Mon" Ta Li "\&%b %a" Ta Li "Mon Dec 1 12:19:47 EDT 1986"
207 .It Li "Jan Wed 1989" Ta Li "\&%b \&%a \&%Y" Ta Li "Wed Jan 4 12:19:47 EST 1989"
208 .It Li "Fri 9" Ta Li "\&%a \&%H" Ta Li "Fri Sep 26 09:00:00 EDT 1986"
209 .It Li "Feb 10:30" Ta Li "\&%b \&%H:\&%S" Ta Li "Sun Feb 1 10:00:30 EST 1987"
210 .It Li 10:30 Ta Li "\&%H:\&%M" Ta Li "Tue Sep 23 10:30:00 EDT 1986"
211 .It Li 13:30 Ta Li "\&%H:\&%M" Ta Li "Tue Sep 22 13:30:00 EDT 1986"
233 interface is inherently unsafe for multi-threaded programs or libraries,
234 since it returns a pointer to a static variable and uses a global state