Back to index

php5  5.3.10
Defines | Functions | Variables
cdf_time.c File Reference
#include "file.h"
#include <time.h>
#include <string.h>
#include "cdf.h"

Go to the source code of this file.

Defines

#define isleap(y)

Functions

static int cdf_getdays (int year)
static int cdf_getday (int year, int days)
static int cdf_getmonth (int year, int days)
int cdf_timestamp_to_timespec (struct timeval *ts, cdf_timestamp_t t)
int cdf_timespec_to_timestamp (cdf_timestamp_t *t, const struct timeval *ts)

Variables

static const int mdays []

Define Documentation

#define isleap (   y)
Value:
((((y) % 4) == 0) && \
    ((((y) % 100) != 0) || (((y) % 400) == 0)))

Definition at line 41 of file cdf_time.c.


Function Documentation

static int cdf_getday ( int  year,
int  days 
) [static]

Definition at line 67 of file cdf_time.c.

{
       size_t m;

       for (m = 0; m < sizeof(mdays) / sizeof(mdays[0]); m++) {
              int sub = mdays[m] + (m == 1 && isleap(year));
              if (days < sub)
                     return days;
              days -= sub;
       }
       return days;
}

Here is the caller graph for this function:

static int cdf_getdays ( int  year) [static]

Definition at line 52 of file cdf_time.c.

{
       int days = 0;
       int y;

       for (y = CDF_BASE_YEAR; y < year; y++)
              days += isleap(y) + 365;
              
       return days;
}

Here is the caller graph for this function:

static int cdf_getmonth ( int  year,
int  days 
) [static]

Definition at line 84 of file cdf_time.c.

{
       size_t m;

       for (m = 0; m < sizeof(mdays) / sizeof(mdays[0]); m++) {
              days -= mdays[m];
              if (m == 1 && isleap(year))
                     days--;
              if (days <= 0)
                     return (int)m;
       }
       return (int)m;
}

Here is the caller graph for this function:

int cdf_timespec_to_timestamp ( cdf_timestamp_t t,
const struct timeval *  ts 
)

Definition at line 146 of file cdf_time.c.

{
       (void)&t;
       (void)&ts;
#ifdef notyet
       struct tm tm;
       if (gmtime_r(&ts->ts_sec, &tm) == NULL) {
              errno = EINVAL;
              return -1;
       }
       *t = (ts->ts_usec / CDF_TIME_PREC) * CDF_TIME_PREC;
       *t = tm.tm_sec;
       *t += tm.tm_min * 60;
       *t += tm.tm_hour * 60 * 60;
       *t += tm.tm_mday * 60 * 60 * 24;
#endif
       return 0;
}
int cdf_timestamp_to_timespec ( struct timeval *  ts,
cdf_timestamp_t  t 
)

Definition at line 99 of file cdf_time.c.

{
       struct tm tm;
#ifdef HAVE_STRUCT_TM_TM_ZONE
       static char UTC[] = "UTC";
#endif
       int rdays;

       /* Time interval, in microseconds */
       ts->tv_usec = (t % CDF_TIME_PREC) * CDF_TIME_PREC;

       t /= CDF_TIME_PREC;
       tm.tm_sec = t % 60;
       t /= 60;

       tm.tm_min = t % 60;
       t /= 60;

       tm.tm_hour = t % 24;
       t /= 24;

       /* XXX: Approx */
       tm.tm_year = CDF_BASE_YEAR + (t / 365);

       rdays = cdf_getdays(tm.tm_year);
       t -= rdays;
       tm.tm_mday = cdf_getday(tm.tm_year, t);
       tm.tm_mon = cdf_getmonth(tm.tm_year, t);
       tm.tm_wday = 0;
       tm.tm_yday = 0;
       tm.tm_isdst = 0;
#ifdef HAVE_STRUCT_TM_TM_GMTOFF
       tm.tm_gmtoff = 0;
#endif
#ifdef HAVE_STRUCT_TM_TM_ZONE
       tm.tm_zone = UTC;
#endif
       tm.tm_year -= 1900;
       ts->tv_sec = mktime(&tm);
       if (ts->tv_sec == -1) {
              errno = EINVAL;
              return -1;
       }
       return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

const int mdays[] [static]
Initial value:
 {
    31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31
}

Definition at line 44 of file cdf_time.c.