Museum

Home

Lab Overview

Retrotechnology Articles

Online Manuals

⇒ getdate_r(3C) — HP-UX 10.20

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

ctime(3C)

ctype(3C)

setlocale(3C)

strftime(3C)

getdate(3C)

NAME

getdate(), getdate_r() − convert user format date and time

SYNOPSIS

#include <time.h>

struct tm *getdate(const char *string);

extern int getdate_err;

int getdate_r(const char *string, struct tm *result, int *errnum);

DESCRIPTION

The getdate() function 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(3C)).

The getdate_r() function expects to be passed the address of a struct tm and stores the result at the supplied address.  A −1 is returned if an error is encountered and the variable pointed to by *errnum is set to indicate the error as described for getdate_err below.  If the operation is successful, 0 is returned. 

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.  DATEMSK should be set to indicate the full path name of the template file.  The first line in the template that matches the input specification is used for interpretation and conversion into the internal time format.  Upon successful completion, getdate() returns a pointer to a struct tm; otherwise, it returns NULL and the external variable getdate_err is set to indicate the error. 

The following field descriptors are supported:

%% same as %

%a abbreviated weekday name

%A full weekday name

%b abbreviated month name

%B full month name

%c locale’s appropriate date and time representation

%d day of the month (01 through 31; the leading 0 is optional)

%e same as %d

%D date as %m/%d/%y

%h abbreviated month name

%H hour (00 through 23)

%I hour (01 through 12)

%m month number (01 through 12)

%M minute (00 through 59)

%n same as \n

%p locale’s equivalent of either AM or PM

%r time as %I:%M:%S %p

%R time as %H:%M

%S seconds (00 through 61)

%t insert a tab

%T time as %H:%M:%S

%w weekday number (Sunday = 0 through Saturday = 6)

%x locale’s appropriate date representation

%X locale’s appropriate time representation

%y year without century (00 through 99)

%Y year as ccyy (e.g., 1986)

%Z time zone name or no characters if no time zone exists.  If the time zone supplied by %Z is not the same as the time zone getdate() expects, an invalid specification error is returned.  getdate() calculates the expected time zone from the TZ environment variable. 

Month and weekday names may consist of any combination of uppercase and lowercase letters.  The user can request that the input date or time specification be in a specific language by setting the LC_TIME category (see setlocale(3C)).

For descriptors that allow leading zeros, leading zeros are optional.  However, the number of digits used for those descriptors must not exceed two, including leading zeros.  Extra whitespace in either the template file or in string is ignored. 

The field descriptors %c, %x, and %X are not supported if they include unsupported field descriptors. 

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 18, 1987, 10:30:30");
getdate("24,9,1986 10:30");
getdate("at monday the 1st of december
getdate("run job at 3 PM, december

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:

1tdate("freitag den 10. oktober 1986 10.30 Uhr");

This example shows how local date and time specification can be defined in the template:

Invocation Line in Template
getdate("11/27/86") %m/%d/%y
getdate("27.11.86") %d.%m.%y
getdate("86-11-27") %y-%m-%d
getdate("Friday 12:00:00") %A %H:%M:%S

The following rules apply when converting the input specification into the internal format:

• If only the weekday is given, today is assumed if the given day is equal to the current day, and next week if it is less. 

• If only the month is given, the current month is assumed if the given month is equal to the current month, and next year if it is less and no year is given (the first day of the month is assumed if no day is given). 

• If no hour, minute and second are given, the current hour, minute and second are assumed. 

• If no date is given, today is assumed if the given hour is greater than the current hour and tomorrow is assumed if it is less. 

The following examples help to illustrate the above rules assuming that the current date is Mon Sep 22 12:19:47 EDT 1986, and the LC_TIME category is set to the default C locale. 

Line in
Input 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:30:00 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

ERRORS

Upon failure, getdate() returns NULL and the variable getdate_err is set to indicate the error. 

The following is a complete list of the getdate_err settings and their interpretation:

1 the DATEMSK environment variable is null or undefined,

2 the template file cannot be opened for reading,

3 failed to get file status information,

4 the template file is not a regular file,

5 an error is encountered while reading the template file,

6 memory allocation failed (not enough memory available),

7 there is no line in the template that matches the input,

8 invalid input specification (example: February 31). 

WARNINGS

The return value for getdate() points to static data whose content is overwritten by each call.  Thus, getdate() is unsafe in multi-thread applications.  getdate_r() is MT-Safe and should be used instead. 

SEE ALSO

ctime(3C), ctype(3C), setlocale(3C), strftime(3C). 

Hewlett-Packard Company  —  HP-UX Release 10.20:  July 1996

Typewritten Software • bear@typewritten.org • Edmonds, WA 98026