1PARSEDATE(3) Library Functions Manual PARSEDATE(3)
2
3
4
6 parsedate - convert time and date string to number
7
9 #include <sys/types.h>
10
11 typedef struct _TIMEINFO {
12 time_t time;
13 long usec;
14 long tzone;
15 } TIMEINFO;
16
17 time_t
18 parsedate(text, now)
19 char *text;
20 TIMEINFO *now;
21
23 Parsedate converts many common time specifications into the number of
24 seconds since the epoch — i.e., a time_t; see time(2).
25
26 Parsedate returns the time, or -1 on error. Text is a character string
27 containing the time and date. Now is a pointer to the time that should
28 be used for calculating relative dates. If now is NULL, then GetTime‐
29 Info in libinn(3) is used to obtain the current time and timezone.
30
31 The character string consists of zero or more specifications of the
32 following form:
33
34 time A time of day, which is of the form hh[:mm[:ss]] [meridian]
35 [zone] or hhmm [meridian] [zone]. If no meridian is specified,
36 hh is interpreted on a 24-hour clock.
37
38 date A specific month and day with optional year. The acceptable
39 formats are mm/dd[/yy], yyyy/mm/dd, monthname dd[, yy], dd mon‐
40 thname [yy], and day, dd monthname yy. The default year is the
41 current year. If the year is less then 100, then 1900 is added
42 to it; if it is less then 21, then 2000 is added to it.
43
44 relative time
45 A specification relative to the current time. The format is
46 number unit; acceptable units are year, month, week, day, hour,
47 minute (or min), and second (or sec). The unit can be specified
48 as a singular or plural, as in 3 weeks.
49
50 The actual date is calculated according to the following steps. First,
51 any absolute date and/or time is processed and converted. Using that
52 time as the base, day-of-week specifications are added. Next, relative
53 specifications are used. If a date or day is specified, and no abso‐
54 lute or relative time is given, midnight is used. Finally, a correc‐
55 tion is applied so that the correct hour of the day is produced after
56 allowing for daylight savings time differences.
57
58 Parsedate ignores case when parsing all words; unknown words are taken
59 to be unknown timezones, which are treated as GMT. The names of the
60 months and days of the week can be abbreviated to their first three
61 letters, with optional trailing period. Periods are ignored in any
62 timezone or meridian values.
63
65 Parsedate does not accept all desirable and unambiguous constructions.
66 Semantically incorrect dates such as ``February 31'' are accepted.
67
68 Daylight savings time is always taken as a one-hour change which is
69 wrong for some places. The daylight savings time correction can get
70 confused if parsing a time within an hour of when the reckoning
71 changes, or if given a partial date.
72
74 Originally written by Steven M. Bellovin <smb@research.att.com> while
75 at the University of North Carolina at Chapel Hill and distributed
76 under the name getdate.
77
78 A major overhaul was done by Rich $alz <rsalz@bbn.com> and Jim Berets
79 <jberets@bbn.com> in August, 1990.
80
81 It was further revised (primarily to remove obsolete constructs and
82 timezone names) a year later by Rich (now <rsalz@osf.org>) for Inter‐
83 NetNews, and the name was changed. This is revision 6312, dated
84 2003-05-04.
85
87 date(1), ctime(3), libinn(3), time(2).
88
89
90
91 PARSEDATE(3)