Convert user format date and time.
Standard C Library (libc.a)
#include <time.h> struct tm *getdate (const char *string) extern int getdate_err
The getdate subroutine converts user definable date and/or time specifications pointed to by string, into a struct tm. The structure declaration is in the time.h header file (see ctime subroutine).
User supplied templates are used to parse and interpret the input string. The templates are contained in text files created by the user and identified by the environment variable DATEMSK. The DATEMSK variable should be set to indicate 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 conversation into the internal time format.
The templates should follow a format where complex field descriptors are preceded by simpler ones. For example:
%M %H:%M %m/%d/%y %m/%d/%y %H:%M:%S
The following field descriptors are supported:
The match between the template and input specification performed by the getdate subroutine is case sensitive.
The month and weekday names can consist of any combination of upper and lower case letters. The used can request that the input date or time specification be in a specific language by setting the LC_TIME category (See the setlocale subroutine).
Leading zero's are not necessary for the descriptors that allow leading zero's. However, at most two digits are allowed for those descriptors, including leading zero's. Extra whitespace in either the template file or in string is ignored.
The field descriptors %c, %x, and %X will not be supported if they include unsupported field descriptors.
Example 1 is an example of a template. Example 2 contains valid input specifications for the template. Example 3 shows how local date and time specifications can be defined in the template.
The following rules apply for converting the input specification into the internal format:
Upon successful completion, the getdate subroutine returns a pointer to struct tm; otherwise, it returns a null pointer and the external variable getdate_err is set to indicate the error.
Upon failure, a null pointer is returned and the variable getdate_err is set to indicate the error.
The following is a complete list of the getdate_err settings and their corresponding descriptions:
%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
getdate ("10/1/87 4 PM") getdate ("Friday") getdate ("Friday September 18, 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 LC_TIME category is set to a German locale that includes freitag as a weekday name and oktober as a month name, the following would be valid:
getdate ("freitag den 10. oktober 1986 10.30 Uhr")
Invocation | Line in Template |
---|---|
getdate ("11/27/86") | %m/%d/%y |
getdate ("27.11.86"0 | %d.%m.%y |
getdate ("86-11-27") | %y-%m-%d |
getdate ("Friday 12:00:00") | %A %H:%M:%S |
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 Sep1 12:19:47 EDT 1986 |
January | %B | Thu Jan 1 12:19:47 EDT 1986 |
December | %B | Mon Dec 1 12:19:47 EDT 1986 |
Sep Mon | %b %a | Mon Sep 1 12:19:47 EDT 1986 |
Jan Fri | %b %a | Fri Jan 2 12:19:47 EDT 1986 |
Dec Mon | %b %a | Mon Dec 1 12:19:47 EDT 1986 |
Jan Wed 1989 | %b %a %Y | Wed Jan 4 12:19:47 EDT 1986 |
Fri 9 | %a %H | Fri Sep 26 12:19:47 EDT 1986 |
Feb 10:30 | %b %H: %S | Sun Feb 1 12:19:47 EDT 1986 |
10:30 | %H: %M | Tue Sep 23 12:19:47 EDT 1986 |
13:30 | %H: %M | Mon Sep 22 12:19:47 EDT 1986 |
The ctime (ctime, localtime, gmtime, mktime, difftime, asctime, or tzset Subroutine), ctype (ctype, isalpha, isupper, islower, isdigit, isxdigit, isalnum, isspace, ispunct, isprint, isgraph, iscntrl, or isascii Subroutines), setlocale, strftime, and times (getrusage, getrusage64, times, or vtimes Subroutine) subroutines.