1GETDATE(3) Library Functions Manual GETDATE(3)
2
3
4
6 getdate - convert time and date from ASCII
7
9 #include <sys/types.h>
10 #include <sys/timeb.h>
11
12 time_t getdate(buf, now)
13 char *buf;
14 struct timeb *now;
15
17 Getdate is a routine that converts most common time specifications to
18 standard UNIX format. The first argument is the character string con‐
19 taining the time and date; the second is the assumed current time (used
20 for relative specifications); if NULL is passed, ftime(2) is used to
21 obtain the current time and timezone.
22
23 The character string consists of 0 or more specifications of the fol‐
24 lowing form:
25
26 tod A tod is a time of day, which is of the form hh:mm[:ss] (or
27 hhmm) [meridian] [zone]. If no meridian - am or pm - is speci‐
28 fied, a 24-hour clock is used. A tod may be specified as just
29 hh followed by a meridian.
30
31 date A date is a specific month and day, and possibly a year.
32 Acceptable formats are mm/dd[/yy] and monthname dd[, yy] If
33 omitted, the year defaults to the current year; if a year is
34 specified as a number less than 100, 1900 is added. If a number
35 not followed by a day or relative time unit occurs, it will be
36 interpreted as a year if a tod, monthname, and dd have already
37 been specified; otherwise, it will be treated as a tod. This
38 rule allows the output from date(1) or ctime(3) to be passed as
39 input to getdate.
40
41 day A day of the week may be specified; the current day will be used
42 if appropriate. A day may be preceeded by a number, indicating
43 which instance of that day is desired; the default is 1. Nega‐
44 tive numbers indicate times past. Some symbolic numbers are
45 accepted: last, next, and the ordinals first through twelfth
46 (second is ambiguous, and is not accepted as an ordinal number).
47 The symbolic number next is equivalent to 2; thus, next monday
48 refers not to the immediately coming Monday, but to the one a
49 week later.
50
51 relative time
52 Specifications relative to the current time are also accepted.
53 The format is [number] unit; acceptable units are year, month,
54 fortnight, week, day, hour, minute, and second.
55
56 The actual date is formed as follows: first, any absolute date and/or
57 time is processed and converted. Using that time as the base, day-of-
58 week specifications are added; last, relative specifications are used.
59 If a date or day is specified, and no absolute or relative time is
60 given, midnight is used. Finally, a correction is applied so that the
61 correct hour of the day is produced after allowing for daylight savings
62 time differences.
63
64 Getdate accepts most common abbreviations for days, months, etc.; in
65 particular, it will recognize them with upper or lower case first let‐
66 ter, and will recognize three-letter abbreviations for any of them,
67 with or without a trailing period. Units, such as weeks, may be speci‐
68 fied in the singular or plural. Timezone and meridian values may be in
69 upper or lower case, and with or without periods.
70
72 /usr/lib/libu.a
73
75 ctime(3), time(2)
76
78 Steven M. Bellovin (unc!smb)
79 Dept. of Computer Science
80 University of North Carolina at Chapel Hill
81
83 Because yacc(1) is used to parse the date, getdate cannot be used a
84 subroutine to any program that also needs yacc.
85 The grammar and scanner are rather primitive; certain desirable and
86 unambiguous constructions are not accepted. Worse yet, the meaning of
87 some legal phrases is not what is expected; next week is identical to 2
88 weeks.
89 The daylight savings time correction is not perfect, and can get con‐
90 fused if handed times between midnight and 2:00 am on the days that the
91 reckoning changes.
92 Because localtime(2) accepts an old-style time format without zone
93 information, attempting to pass getdate a current time containing a
94 different zone will probably fail.
95
96
97
98 unc GETDATE(3)