summaryrefslogtreecommitdiff
path: root/lib/libutil/parsedate.3
blob: 2bfde56729cbdc2990c6333519935b10d998c5d6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
.\"     $NetBSD: parsedate.3,v 1.5 2009/03/10 21:01:08 joerg Exp $
.\"
.\" Copyright (c) 2006 The NetBSD Foundation, Inc.
.\" All rights reserved.
.\"
.\" This code is derived from software contributed to The NetBSD Foundation
.\" by Christos Zoulas.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
.\" are met:
.\" 1. Redistributions of source code must retain the above copyright
.\"    notice, this list of conditions and the following disclaimer.
.\" 2. Redistributions in binary form must reproduce the above copyright
.\"    notice, this list of conditions and the following disclaimer in the
.\"    documentation and/or other materials provided with the distribution.
.\"
.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
.\" PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
.\" POSSIBILITY OF SUCH DAMAGE.
.\"
.Dd November 17, 2006
.Dt PARSEDATE 3
.Os
.Sh NAME
.Nm parsedate
.Nd date parsing function
.Sh LIBRARY
.Lb libutil
.Sh SYNOPSIS
.In util.h
.Ft time_t
.Fn parsedate "const char *datestr" "const time_t *time" "const int *tzoff"
.Sh DESCRIPTION
The
.Nm parsedate
function parses a datetime from
.Ar datestr
described in english relative to an optional
.Ar time
point and an optional timezone offset in seconds specified in
.Ar tzoff .
If either
.Ar time
or
.Ar tzoff
are
.Dv NULL ,
then the current time and timezone offset are used.
.Pp
The
.Ar datestr
is a sequence of white-space separated items.
The white-space is optional the concatenated items are not ambiguous.
An empty
.Ar datestr
is equivalent to midnight today (the beginning of this day).
.Pp
The following words have the indicated numeric meanings:
.Dv last =
\-1,
.Dv this =
0,
.Dv first or next
1,
.Dv second
is unused so that it is not confused with
.Dq seconds ,
.Dv third =
3,
.Dv fourth =
4,
.Dv fifth =
5,
.Dv sixth =
6,
.Dv seventh =
7,
.Dv eighth =
8,
.Dv ninth =
9,
.Dv tenth =
10,
.Dv eleventh =
11,
.Dv twelfth =
12.
.Pp
The following words are recognized in English only:
.Dv AM ,
.Dv PM ,
.Dv a.m. ,
.Dv p.m.
.Pp
The months:
.Dv january ,
.Dv february ,
.Dv march ,
.Dv april ,
.Dv may ,
.Dv june ,
.Dv july ,
.Dv august ,
.Dv september ,
.Dv sept ,
.Dv october ,
.Dv november ,
.Dv december ,
.Pp
The days of the week:
.Dv sunday ,
.Dv monday ,
.Dv tuesday ,
.Dv tues ,
.Dv wednesday ,
.Dv wednes ,
.Dv thursday ,
.Dv thur ,
.Dv thurs ,
.Dv friday ,
.Dv saturday .
.Pp
Time units:
.Dv year ,
.Dv month ,
.Dv fortnight ,
.Dv week ,
.Dv day ,
.Dv hour ,
.Dv minute ,
.Dv min ,
.Dv second ,
.Dv sec ,
.Dv tomorrow ,
.Dv yesterday .
.Pp
Timezone names:
.Dv gmt ,
.Dv ut ,
.Dv utc ,
.Dv wet ,
.Dv bst ,
.Dv wat ,
.Dv at ,
.Dv ast ,
.Dv adt ,
.Dv est ,
.Dv edt ,
.Dv cst ,
.Dv cdt ,
.Dv mst ,
.Dv mdt ,
.Dv pst ,
.Dv pdt ,
.Dv yst ,
.Dv ydt ,
.Dv hst ,
.Dv hdt ,
.Dv cat ,
.Dv ahst ,
.Dv nt ,
.Dv idlw ,
.Dv cet ,
.Dv met ,
.Dv mewt ,
.Dv mest ,
.Dv swt ,
.Dv sst ,
.Dv fwt ,
.Dv fst ,
.Dv eet ,
.Dv bt ,
.Dv zp4 ,
.Dv zp5 ,
.Dv zp6 ,
.Dv wast ,
.Dv wadt ,
.Dv cct ,
.Dv jst ,
.Dv east ,
.Dv eadt ,
.Dv gst ,
.Dv nzt ,
.Dv nzst ,
.Dv nzdt ,
.Dv idle .
.Pp
A variety of unambiguous dates are recognized:
.Bl -tag -compact -width "20 Jun 1994"
.It 69-09-10
For years between 69-99 we assume 1900+ and for years between 0-68
we assume 2000+.
.It 2006-11-17
An ISO-8601 date.
.It 10/1/2000
October 10, 2000; the common US format.
.It 20 Jun 1994
.It 23jun2001
.It 1-sep-06
Other common abbreviations.
.It 1/11
the year can be omitted
.El
.Pp
As well as times:
.Bl -tag -compact -width 12:11:01.000012
.It 10:01
.It 10:12pm
.It 12:11:01.000012
.It 12:21-0500
.El
.Pp
Relative items are also supported:
.Bl -tag -compact -width "this thursday"
.It -1 month
.It last friday
.It one week ago
.It this thursday
.It next sunday
.It +2 years
.El
.Sh RETURN VALUES
.Fn parsedate
returns the number of seconds passed since the Epoch, or
.Dv \-1
if the date could not be parsed properly.
.Sh SEE ALSO
.Xr date 1 ,
.Xr eeprom 8
.Sh HISTORY
The parser used in
.Fn parsedate
was originally written by Steven M. Bellovin while at the University
of North Carolina at Chapel Hill.
It was later tweaked by a couple of people on Usenet.
Completely overhauled by Rich $alz and Jim Berets in August, 1990.
.Pp
The
.Fn parsedate
function first appeared in
.Nx 4.0 .