| iMatix home page
| << | < | > | >>
SFL Logo SFL
Version 2.11

 

safe_localtime

#include "sfldate.h"
struct tm
*safe_localtime (const time_t *time_secs)

Synopsis

Handles time_t values that exceed 2038. The standard C localtime() function fails on most systems when the date passes 2038.

Source Code - (sfldate.c)

{
    qbyte
        adjusted_time;
    struct tm
        *time_struct;
    int
        adjust_years = 0;

    adjusted_time = (qbyte) *time_secs;
    while (adjusted_time > LONG_MAX)
      {
        adjust_years  += 20;
        adjusted_time -= 631152000;     /*  Number of seconds in 20 years    */
      }
    time_struct = localtime ((const time_t *) &adjusted_time);
    ASSERT (time_struct);               /*  MUST be valid now...             */
    time_struct-> tm_year += adjust_years;

    return (time_struct);
}

| << | < | > | >> iMatix Copyright © 1996-2000 iMatix Corporation