Implementation status: to be implemented
struct tm *getdate(const char *string);
getdate() function converts user format date and time.
string - a string representation of a date or time,
getdate() function converts a string representation of a date or time into a broken-down time.
The external variable
getdate_err, which has type
int, is used by
getdate() to return error values.
Templates are used to parse and interpret the input string. The templates are contained in a text file identified by the environment variable
DATEMSK variable indicates the full pathname of the file that contains the templates. The first line in the template that matches the input specification is used for interpretation and conversion into the internal time format.
The following conversion specifications are supported:
%aAbbreviated weekday name.
%AFull weekday name.
%bAbbreviated month name.
%BFull month name.
%cLocale's appropriate date and time representation.
[00,99]; leading zeros are permitted but not required.
%dDay of month
[01,31]; the leading
%m / %d / %y.
%hAbbreviated month name.
%pLocale's equivalent of either
%rThe locale's appropriate representation of time in
PMnotation. In the POSIX locale, this is equivalent to
%I : %M : %S %p.
%H : %M.
[00,60]. The range goes to
60(rather than stopping at
59) to allow positive leap seconds to be expressed. Since leap seconds cannot be predicted by any algorithm, leap second data must come from some external source.
%H : %M : %S.
(Sunday = [0,6]).
%xLocale's appropriate date representation.
%XLocale's appropriate time representation.
%yYear within century. When a century is not otherwise specified, values in the range
[69,99]refers to years 1969 to 1999 inclusive, and values in the range
[00,68]refer to years
Note: It is expected that in a future version of this standard the default century inferred from a
2-digityear will change. (This would apply to all commands accepting a
2-digityear as input.)
%YYear as "ccyy" (for example,
%ZTimezone name or no characters if no timezone exists. If the timezone supplied by
%Zis not the timezone that
getdate()expects, an invalid input specification error results. The
getdate()function calculates an expected timezone based on information supplied to the function (such as the hour, day, and month).
The match between the template and input specification performed by
getdate() is case-insensitive.
The month and weekday names can consist of any combination of upper and lowercase letters. The process can request that the input date or time specification be in a specific language by setting the
LC_TIME category (see
Leading zeros are not necessary for the descriptors that allow leading zeros. However, at most two digits are allowed for those descriptors, including leading zeros. Extra white space in either the template file or in string are ignored.
The results are undefined if the conversion specifications
%X include unsupported conversion specifications.
The following rules apply for converting the input specification into the internal format:
%Zis being scanned, then
getdate()initializes the broken-down time to be the current time in the scanned timezone. Otherwise, it initializes the broken-down time based on the current local time as if
localtime()had been called.
If only the weekday is given, the day chosen is the day, starting with today and moving into the future, which first matches the named day.
If only the month (and no year) is given, the month chosen is the month, starting with the current month and moving into the future, which first matches the named month. The first day of the month shall be assumed if no day is given.
If no hour, minute, and second are given, the current hour, minute, and second is assumed.
If no date is given, the hour chosen shall be the hour, starting with the current hour and moving into the future, which first matches the named hour.
If a conversion specification in the
DATEMSKfile does not correspond to one of the conversion specifications above, the behavior is unspecified.
Upon successful completion,
getdate() shall return a pointer to a struct tm. Otherwise, it shall return a null pointer and set getdate_err to indicate the error.
getdate() function shall fail in the following cases, setting
getdate_err to the value shown in the list below. Any changes to
errno are unspecified.
DATEMSKenvironment variable is null or undefined.
- The template file cannot be opened for reading.
- Failed to get file status information.
- The template file is not a regular file.
- An I/O error is encountered while reading the template file.
- Memory allocation failed (not enough memory available).
- There is no line in the template that matches the input.
- Invalid input specification. For example, February 31; or a time is specified that cannot be represented in a
time_t(representing the time in seconds since the Epoch).
- Implement the
- Implement the