TM(3)

NAME
tm - time conversion support

SYNOPSIS

DESCRIPTION
The tm library supports conversion between string date specifications, clock values and values. and (see ctime(3)) are used to determine local time zone information.

values are the number of seconds since the epoch, Jan 1 00:00:00 GMT 1970, with leap seconds omitted.

The global variable contains flags that allow all programs using the library to be controlled in a consistent manner. is initialized by the routine described below, and may be explicitly reset after is called. The flags are:

Set by
    if and do not compensate for leap seconds.

values are interpreted as if they include leap seconds.
    Set by if the option is set in the environment variable.

Times are relative to
    UTC (universal coordinated time, i.e., GMT). Otherwise times are relative to the local time zone. Set by if the time zone name matches one of through described below. If the time zone name is not determined by then the environment variables (as described in BSD 4.3) and (as described in System V) are checked, in order. If this fails then the time zone name is constructed using the local time zone offset.

The routines are:

Parses the date specification
    using the string table (described below) and returns the equivalent value. If is set to the position of the first unrecognized character in is used to provide default values for omitted components in If is then the current time is used.

Corrects any out of bounds fields in
    and returns as its value. The corrections start with and propagate down to For example, if were 61 then it would change to 1 and would be incremented by 1, and so on. and are not changed as these can be computed from the other fields.

Formats the date pointed to by
    into the buffer according to the format specification If is or empty then the string is used. If is then the current time is used. A pointer to the end of (i.e., the terminating is returned.

    is in the style of printf(3), where %field causes the corresponding fixed size field to be placed in zero padded if necessary, and \c and \nnn sequences are interpreted as in the C language. Otherwise invalid %field specifications and all other characters in are copied into without change. String field values are taken from the string table. The fields are:

    %   % character.
    a   Abbreviated weekday name.
    A   Full weekday name.
    b   Abbreviated month name.
    c   ctime(3) style date without the trailing newline.
    C   date(1) style date.
    d   Day of month number.
    D   Date as mm/dd/yy.
    e   Blank padded day of month number.
    E   Unpadded day of month number.
    h   Abbreviated month name.
    H   24-hour clock hour.
    i   International date(1) date that includes the time zone type name.
    I   12-hour clock hour.
    j   1-offset Julian date.
    J   0-offset Julian date.
    l   ls(1) -l date that lists recent dates with hh:mm and distant dates with yyyy.
    m   Month number.
    M   Minutes.
    n   newline character.
    p   Meridian (e.g., AM or PM).
    r   12-hour time as hh:mm:ss meridian.
    R   24-hour time as hh:mm.
    S   Seconds.
    t   tab character.
    T   24-hour time as hh:mm:ss.
    U   Week number with Sunday as the first day.
    w   Weekday number.
    W   Week number with Monday as the first day.
    x   Local date style, using that includes the month, day and year.
    X   Local time style, using that includes the hours and minutes.
    y   2-digit year.
    Y   4-digit year.
    z   Time zone type name.
    Z   Time zone name.
    +flag
    -flag
        Temporarily (until returns) sets (+) or clears (-) the flags specified by flag:
        l
        u
    #   Number of seconds since the epoch.

Implicitly called by the other
    tm library routines to initialize global data, including the table and the global flags. Global data should only be modified after an explicit call to

Returns a
    value for the time pointed to by with leap seconds adjusted for external routines that do not handle leap seconds. If is then the current time is used. Adjustments are only done if the flag is set in

Returns a pointer to the
    struct corresponding to the time pointed to by If is then the current time is used.

Returns the
    value corresponding to If is then is relative to the local time zone, otherwise is the number of minutes west of UTC with daylight savings time taken into account. and are ignored in the conversion.

The library routines use a table of date strings pointed to by The indices in are fixed by category. may be changed to point to other tables according to local language and date conventions. The contents by index (showing the USA English values) are:

    0-11
        3-character abbreviated month names.
    12-23
        Full month names.
    24-30
        3-character abbreviated weekday names.
    31-37
        Full weekday names.
    38  local time format used by the %X field.
    39  local date format used by the %x field.
    40  format used if the argument is or empty.
    41-42
        Meridian names: AM, PM.
    43-46
        UTC time zone names: GMT, UTC, UCT, CUT.
    47-50
        Daylight savings time suffix names: DST.
    51-54
        Suffixes to be ignored when matching strings in
    55-61
        Time part names: second, hour, minute, day, week, month, year.
    62-65
        Hours of the day names: midnight, morning, noon, evening.
    66-68
        Relative day names: yesterday, today, tomorrow.
    69-71
        Past relative time references: last, ago, past.
    72-75
        Current relative time references: this, now, current.
    75-77
        Future relative time references: next, hence, coming.
    78-80
        Exact relative time references: exactly.
    81-85
        Noise words to be ignored: at, in, on.

Low level support functions and data are described in

EXAMPLES
    #include <tm.h>
    main() {
        int       i;
        time_t    t;
        char      buf[128];
        struct {
            char* date;
            char* format;
        }         x[] = {
            "now",                 "%i",
            "2 months ago",        "%C",
            "this Wednesday noon", "%x %I:%M %p",
            "last December 25",    "%A",
            0,                     0
        };
        for (i = 0; x[i].date; i++) {
            t = tmdate(x[i].date, (char*)0, (time_t*)0);
            (void)tmform(buf, x[i].format, &t);
            puts(buf);
        }
    }
produces
    Fri Sep 30 12:10:14 USA EDT 1988
    Fri Jul  1 00:00:00 EDT 1988
    10/05/88 12:00 PM
    Friday

SEE ALSO
date(1), time(2), ctime(3)

BUGS
values may get clobbered by the tm library routines as the ctime(3) routines typically return pointers to a single static area. uses an internal international time zone name table that will probably always be incomplete.