Chapter Contents

Previous

Next
Function Categories

Timing Functions

The SAS/C library supports all of the ISO/ANSI timing functions. Timing functions allow determination of the current time of day, and the processing and formatting of time values. Programs using any of these functions must include the header file <time.h> .

The POSIX standards mandate several changes to the SAS/C timing functions. As a result, the SAS/C Release 6.00 library assumes a new default epoch and can process time-zone information defined via the TZ environment variable.

In previous releases of SAS/C, time_t values were measured from the 370 epoch, starting at January 1, 1900. In accordance with the POSIX specification, the SAS/C Release 6.00 library measures time from the UNIX epoch, starting at January 1, 1970.

A program with special requirements can specifically define its own epoch by declaring the extern variable _epoch , as in the following example:

#include <time.h>

time_t _epoch = _EPOCH_370;

This declaration specifies the 370 epoch. You can also use the value _EPOCH_UNIX to specify the standard UNIX epoch. Any legitimate time_t value can be used as the epoch, as in this example, which defines the start of the epoch as January 1, 1971:

#include <time.h>

time_t _epoch = _EPOCH_UNIX+365*86400;

Also, if the TZ environment variable is set, the SAS/C mktime , ctime , localtime , and strftime routines will take time-zone information into account. For TSO or CMS programs, TZ may be defined as an external or permanent scope environment variable.

Note:    The TZ environment variable expresses offset from Greenwich mean time. The SAS/C library assumes that the hardware time-of-day clock has been set to accurately reflect Greenwich time, as recommended by the IBM ESA Principles of Operation. If the hardware time-of-day clock does not accurately reflect Greenwich time, then processing of the TZ information will not be correct, and applications depending on accurate local time information may fail.  [cautionend]

The <time.h> header file defines two types that describe time values: time_t and struct tm . The type time_t is a numeric type used to contain time values expressed in the seconds after some implementation-defined base point (or era). The type struct tm is a structure that is produced by several of the timing routines; it contains time and date information in a more readily usable form. The struct tm structure is defined to contain the following components:

int tm_sec;     /* seconds after the minute (0-59)  */
int tm_min;     /* minutes after the hour (0-59)    */
int tm_hour;    /* hours since midnight (0-23)      */
int tm_mday;    /* day of the month (1-31)          */
int tm_mon;     /* months since January (0-11)      */
int tm_year;    /* years since 1900                 */
int tm_wday;    /* days since Sunday (0-6)          */
int tm_yday;    /* days since January 1 (0-365)     */
int tm_isdst;   /* Daylight Savings Time flag.      */

Routines are provided to convert time_t values to struct tm values and to convert either of these types to a formatted string suitable for printing.

The resolution and accuracy of time values vary from implementation to implementation. Timing functions under traditional UNIX C compilers return a value of type long . The library implements time_t as a double to allow more accurate time measurement. Keep this difference in mind for programs ported among several environments.

The timing functions are
asctime convert time structure to character string
clock measure program processor time
ctime convert local time value to character string
difftime compute the difference of two times
gmtime break Greenwich mean time into components
localtime break local time value into components
mktime generate encoded time value
strftime convert time to string
time return the current time
tzset store time zone information.


Chapter Contents

Previous

Next

Top of Page

Copyright © 2001 by SAS Institute Inc., Cary, NC, USA. All rights reserved.