1GETDATE(3) Linux Programmer's Manual GETDATE(3)
2
3
4
6 getdate - convert a string to struct tm
7
9 #define _XOPEN_SOURCE
10 #define _XOPEN_SOURCE_EXTENDED
11 #include <time.h>
12
13 struct tm *getdate (const char *string);
14
15 extern int getdate_err;
16
17
18 #define _GNU_SOURCE
19 #include <time.h>
20
21 int getdate_r (const char *string, struct tm *res);
22
24 The function getdate() converts a string pointed to by string into the
25 tm structure that it returns. This tm structure may be found in static
26 storage, so that it will be overwritten by the next call.
27
28 In contrast to strptime(3), (which has a format argument), getdate()
29 uses the formats found in the file of which the full pathname is given
30 in the environment variable DATEMSK. The first line in the file that
31 matches the given input string is used for the conversion.
32
33 The matching is done case insensitively. Superfluous whitespace,
34 either in the pattern or in the string to be converted, is ignored.
35
36 The conversion specifications that a pattern can contain are those
37 given for strptime(3). One more conversion specification is accepted:
38
39 %Z Timezone name.
40
41 When %Z is given, the value to be returned is initialised to the bro‐
42 ken-down time corresponding to the current time in the given time zone.
43 Otherwise, it is initialised to the broken-down time corresponding to
44 the current local time.
45
46 When only the weekday is given, the day is taken to be the first such
47 day on or after today.
48
49 When only the month is given (and no year), the month is taken to be
50 the first such month equal to or after the current month. If no day is
51 given, it is the first day of the month.
52
53 When no hour, minute and second are given, the current hour, minute and
54 second are taken.
55
56 If no date is given, but we know the hour, then that hour is taken to
57 be the first such hour equal to or after the current hour.
58
60 When successful, this function returns a pointer to a struct tm. Oth‐
61 erwise, it returns NULL and sets the global variable getdate_err.
62 Changes to errno are unspecified. The following values for getdate_err
63 are defined:
64
65 1 The DATEMSK environment variable is null or undefined.
66
67 2 The template file cannot be opened for reading.
68
69 3 Failed to get file status information.
70
71 4 The template file is not a regular file.
72
73 5 An error is encountered while reading the template file.
74
75 6 Memory allocation failed (not enough memory available).
76
77 7 There is no line in the file that matches the input.
78
79 8 Invalid input specification.
80
82 Since getdate() is not reentrant because of the use of getdate_err and
83 the static buffer to return the result in, glibc provides a thread-safe
84 variant. The functionality is the same. The result is returned in the
85 buffer pointed to by res and in case of an error the return value is
86 non-zero with the same values as given above for getdate_err.
87
88 The POSIX.1-2001 specification for strptime() contains conversion spec‐
89 ifications using the %E or %O modifier, while such specifications are
90 not given for getdate(). The glibc implementation implements getdate()
91 using strptime() so that automatically precisely the same conversions
92 are supported by both.
93
94 The glibc implementation does not support the %Z conversion specifica‐
95 tion.
96
98 DATEMSK
99 File containing format patterns.
100
101 TZ, LC_TIME
102 Variables used by strptime().
103
105 POSIX.1-2001
106
108 localtime(3), setlocale(3), strftime(3), strptime(3), time(3), fea‐
109 ture_test_macros(7)
110
111
112
113 2001-12-26 GETDATE(3)