struct tm getdate(const char string);
extern int getdate_err;
User-supplied templates are used to parse and interpret the input string. The templates are text files created by the user and identified via the environment variable DATEMSK. Each line in the template represents an acceptable date and/or time specification using some of the same field descriptors as the ones used by the date command. The first line in the template that matches the input specification is used for interpretation and conversion into the internal time format. If successful, the function getdate returns a pointer to a tm structure; otherwise, it returns NULL and sets the global variable getdate_err to indicate the error.
The following field descriptors are supported:
ccyy(for example, 1986)
The month and weekday names can consist of any combination of upper- and lowercase letters. Any strings the user puts in are case-insensitive. For example, a string Uhr (as shown below) would be treated the same way as a string uhr. The user can request that the input date or time specification be in a specific language by setting the categories LC_TIME and LC_CTYPE of setlocale.
The following example shows the possible contents of a template:
%m %A %B %d %Y, %H:%M:%S %A %B %m/%d/%y %I %p %d,%m,%Y %H:%M at %A the %dst of %B in %Y run job at %I %p,%B %dnd %A den %d. %B %Y %H.%M Uhr
The following are examples of valid input specifications for the above template:
getdate("10/1/87 4 PM") getdate("Friday") getdate("Friday September 19 1987, 10:30:30") getdate("24,9,1986 10:30") getdate("at monday the 1st of december in 1986") getdate("run job at 3 PM, december 2nd")
If the LANG environment variable is set to german, the following is valid:
getdate("freitag den 10. oktober 1986 10.30 Uhr")
Local time and date specification are also supported. The following examples show how local date and time specification can be defined in the template.
|Invocation||Line in Template|
|getdate("Friday 12:00:00")||%A %H:%M:%S|
The following rules are applied for converting the input specification into the internal format:
The following examples illustrate the above rules. Assume that the current date is Mon Sep 22 12:19:47 EDT 1986 and that the LC_TIME and LANG environment variables are not set.
|Input||Line in Template||Date|
|Mon||%a||Mon Sep 22 12:19:47 EDT 1986|
|Sun||%a||Sun Sep 28 12:19:47 EDT 1986|
|Fri||%a||Fri Sep 26 12:19:47 EDT 1986|
|September||%B||Mon Sep 1 12:19:47 EDT 1986|
|January||%B||Thu Jan 1 12:19:47 EST 1987|
|December||%B||Mon Dec 1 12:19:47 EST 1986|
|Sep Mon||%b %a||Mon Sep 1 12:19:47 EDT 1986|
|Jan Fri||%b %a||Fri Jan 2 12:19:47 EST 1987|
|Dec Mon||%b %a||Mon Dec 1 12:19:47 EST 1986|
|Jan Wed 1989||%b %a %Y||Wed Jan 4 12:19:47 EST 1989|
|Fri 9||%a %H||Fri Sep 26 09:00:00 EDT 1986|
|Feb 10:30||%b %H:%S||Sun Feb 1 10:00:30 EST 1987|
|10:30||%H:%M||Tue Sep 23 10:30:00 EDT 1986|
|13:30||%H:%M||Mon Sep 22 13:30:00 EDT 1986|
The following is a complete list of the getdate_err settings and their meanings.
Subsequent calls to getdate alter the contents of getdate_err.
getdate makes explicit use of macros described in ctype(3C) and is thus affected by the LC_CTYPE category of the current locale.
Previous implementations of getdate may return char*.
If the time zone supplied by %Z is not the same as the time zone getdate expects, an invalid input specification error will result. getdate calculates an expected time zone based on information supplied to the interface (such as hour, day, and month).