Manual browser: parsedate(3)

Section:
Page:
PARSEDATE(3) Library Functions Manual PARSEDATE(3)

NAME

parsedatedate parsing function

LIBRARY

System Utilities Library (libutil, -lutil)

SYNOPSIS

#include <util.h>

time_t
parsedate(const char *datestr, const time_t *time, const int *tzoff);

DESCRIPTION

The parsedate() function parses a datetime from datestr described in English relative to an optional time point, and an optional timezone offset (in minutes behind/west of UTC) specified in tzoff. If time is NULL then the current time is used. If tzoff is NULL, then the current time zone is used.

The datestr is a sequence of white-space separated items. The white-space is optional the concatenated items are not ambiguous. An empty datestr is equivalent to midnight today (the beginning of this day).

The following words have the indicated numeric meanings: last = -1, this = 0, first, next, or one = 1, second is unused so that it is not confused with “seconds”, two = 2, third or three = 3, fourth or four = 4, fifth or five = 5, sixth or six = 6, seventh or seven = 7, eighth or eight = 8, ninth or nine = 9, tenth or ten = 10, eleventh or eleven = 11, twelfth or twelve = 12.

The following words are recognized in English only: AM, PM, a.m., p.m.

The months: january, february, march, april, may, june, july, august, september, sept, october, november, december,

The days of the week: sunday, monday, tuesday, tues, wednesday, wednes, thursday, thur, thurs, friday, saturday.

Time units: year, month, fortnight, week, day, hour, minute, min, second, sec, tomorrow, yesterday.

Timezone names: gmt, ut, utc, wet, bst, wat, at, ast, adt, est, edt, cst, cdt, mst, mdt, pst, pdt, yst, ydt, hst, hdt, cat, ahst, nt, idlw, cet, met, mewt, mest, swt, sst, fwt, fst, eet, bt, zp4, zp5, zp6, wast, wadt, cct, jst, east, eadt, gst, nzt, nzst, nzdt, idle.

A variety of unambiguous dates are recognized:

9/10/69
For years between 69-99 we assume 1900+ and for years between 0-68 we assume 2000+.
2006-11-17
An ISO-8601 date.
69-09-10
The year in an ISO-8601 date is always taken literally, so this is the year 69, not 2069.
10/1/2000
October 10, 2000; the common US format.
20 Jun 1994
23jun2001
1-sep-06
Other common abbreviations.
1/11
The year can be omitted. This is the US month/day format.

As well as times:

10:01
10:12pm
12:11:01.000012
12:21-0500

Relative items are also supported:

-1 month
last friday
one week ago
this thursday
next sunday
+2 years

Seconds since epoch (also known as UNIX time) are also supported:

@735275209
Tue Apr 20 03:06:49 UTC 1993

RETURN VALUES

parsedate() returns the number of seconds passed since the Epoch, or -1 if the date could not be parsed properly. A non-error result of -1 can be distinguished from an error by setting errno to 0 before calling parsedate(), and checking the value of errno afterwards.

HISTORY

The parser used in 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.

The parsedate() function first appeared in NetBSD 4.0.

BUGS

1
The parsedate() function is not re-entrant or thread-safe.
2
The parsedate() function cannot compute days before the unix epoch (19700101).
3
The parsedate() function assumes years less than 0 mean - year, years less than 70 mean 2000 + year, years less than 100 mean 1900 + year.
October 8, 2014 NetBSD 7.0