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