xref: /minix3/lib/libutil/parsedate.3 (revision 58a2b0008e28f606a7f7f5faaeaba4faac57a1ea)
1.\"     $NetBSD: parsedate.3,v 1.10 2010/12/22 09:12:28 wiz Exp $
2.\"
3.\" Copyright (c) 2006 The NetBSD Foundation, Inc.
4.\" All rights reserved.
5.\"
6.\" This code is derived from software contributed to The NetBSD Foundation
7.\" by Christos Zoulas.
8.\"
9.\" Redistribution and use in source and binary forms, with or without
10.\" modification, are permitted provided that the following conditions
11.\" are met:
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.
17.\"
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.
29.\"
30.Dd December 20, 2010
31.Dt PARSEDATE 3
32.Os
33.Sh NAME
34.Nm parsedate
35.Nd date parsing function
36.Sh LIBRARY
37.Lb libutil
38.Sh SYNOPSIS
39.In util.h
40.Ft time_t
41.Fn parsedate "const char *datestr" "const time_t *time" "const int *tzoff"
42.Sh DESCRIPTION
43The
44.Fn parsedate
45function parses a datetime from
46.Ar datestr
47described in english relative to an optional
48.Ar time
49point and an optional timezone offset in seconds specified in
50.Ar tzoff .
51If either
52.Ar time
53or
54.Ar tzoff
55are
56.Dv NULL ,
57then the current time and timezone offset are used.
58.Pp
59The
60.Ar datestr
61is a sequence of white-space separated items.
62The white-space is optional the concatenated items are not ambiguous.
63An empty
64.Ar datestr
65is equivalent to midnight today (the beginning of this day).
66.Pp
67The following words have the indicated numeric meanings:
68.Dv last =
69\-1,
70.Dv this =
710,
72.Dv first, next, or one =
731,
74.Dv second
75is unused so that it is not confused with
76.Dq seconds ,
77.Dv two =
782,
79.Dv third or three =
803,
81.Dv fourth or four =
824,
83.Dv fifth or five  =
845,
85.Dv sixth or six  =
866,
87.Dv seventh or seven =
887,
89.Dv eighth or eight =
908,
91.Dv ninth or nine =
929,
93.Dv tenth or ten =
9410,
95.Dv eleventh or eleven =
9611,
97.Dv twelfth or twoelve =
9812.
99.Pp
100The following words are recognized in English only:
101.Dv AM ,
102.Dv PM ,
103.Dv a.m. ,
104.Dv p.m.
105.Pp
106The months:
107.Dv january ,
108.Dv february ,
109.Dv march ,
110.Dv april ,
111.Dv may ,
112.Dv june ,
113.Dv july ,
114.Dv august ,
115.Dv september ,
116.Dv sept ,
117.Dv october ,
118.Dv november ,
119.Dv december ,
120.Pp
121The days of the week:
122.Dv sunday ,
123.Dv monday ,
124.Dv tuesday ,
125.Dv tues ,
126.Dv wednesday ,
127.Dv wednes ,
128.Dv thursday ,
129.Dv thur ,
130.Dv thurs ,
131.Dv friday ,
132.Dv saturday .
133.Pp
134Time units:
135.Dv year ,
136.Dv month ,
137.Dv fortnight ,
138.Dv week ,
139.Dv day ,
140.Dv hour ,
141.Dv minute ,
142.Dv min ,
143.Dv second ,
144.Dv sec ,
145.Dv tomorrow ,
146.Dv yesterday .
147.Pp
148Timezone names:
149.Dv gmt ,
150.Dv ut ,
151.Dv utc ,
152.Dv wet ,
153.Dv bst ,
154.Dv wat ,
155.Dv at ,
156.Dv ast ,
157.Dv adt ,
158.Dv est ,
159.Dv edt ,
160.Dv cst ,
161.Dv cdt ,
162.Dv mst ,
163.Dv mdt ,
164.Dv pst ,
165.Dv pdt ,
166.Dv yst ,
167.Dv ydt ,
168.Dv hst ,
169.Dv hdt ,
170.Dv cat ,
171.Dv ahst ,
172.Dv nt ,
173.Dv idlw ,
174.Dv cet ,
175.Dv met ,
176.Dv mewt ,
177.Dv mest ,
178.Dv swt ,
179.Dv sst ,
180.Dv fwt ,
181.Dv fst ,
182.Dv eet ,
183.Dv bt ,
184.Dv zp4 ,
185.Dv zp5 ,
186.Dv zp6 ,
187.Dv wast ,
188.Dv wadt ,
189.Dv cct ,
190.Dv jst ,
191.Dv east ,
192.Dv eadt ,
193.Dv gst ,
194.Dv nzt ,
195.Dv nzst ,
196.Dv nzdt ,
197.Dv idle .
198.Pp
199A variety of unambiguous dates are recognized:
200.Bl -tag -compact -width "20 Jun 1994"
201.It 69-09-10
202For years between 69-99 we assume 1900+ and for years between 0-68
203we assume 2000+.
204.It 2006-11-17
205An ISO-8601 date.
206.It 10/1/2000
207October 10, 2000; the common US format.
208.It 20 Jun 1994
209.It 23jun2001
210.It 1-sep-06
211Other common abbreviations.
212.It 1/11
213the year can be omitted
214.El
215.Pp
216As well as times:
217.Bl -tag -compact -width 12:11:01.000012
218.It 10:01
219.It 10:12pm
220.It 12:11:01.000012
221.It 12:21-0500
222.El
223.Pp
224Relative items are also supported:
225.Bl -tag -compact -width "this thursday"
226.It -1 month
227.It last friday
228.It one week ago
229.It this thursday
230.It next sunday
231.It +2 years
232.El
233.Pp
234Seconds since epoch (also known as UNIX time) are also supported:
235.Bl -tag -compact -width "@735275209"
236.It @735275209
237Tue Apr 20 03:06:49 UTC 1993
238.El
239.Sh RETURN VALUES
240.Fn parsedate
241returns the number of seconds passed since the Epoch, or
242.Dv \-1
243if the date could not be parsed properly.
244.Sh SEE ALSO
245.Xr date 1 ,
246.Xr eeprom 8
247.Sh HISTORY
248The parser used in
249.Fn parsedate
250was originally written by Steven M. Bellovin while at the University
251of North Carolina at Chapel Hill.
252It was later tweaked by a couple of people on Usenet.
253Completely overhauled by Rich $alz and Jim Berets in August, 1990.
254.Pp
255The
256.Fn parsedate
257function first appeared in
258.Nx 4.0 .
259.Sh BUGS
260.Bl -tag -compact -width 1
261.It 1
262The
263.Fn parsedate
264function is not re-entrant or thread-safe.
265.It 2
266The
267.Fn parsedate
268function cannot compute days before the unix epoch (19700101).
269.It 3
270The
271.Fn parsedate
272function assumes years less than 0 mean -
273.Fa year ,
274years less than 70 mean 2000 +
275.Fa year ,
276years less than 100 mean 1900 +
277.Fa year .
278.El
279