libdali  1.6
 All Classes Files Functions Variables Typedefs Macros Pages
Macros | Functions | Variables
timeutils.c File Reference
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include "libdali.h"

Macros

#define TM_LEAP_CHECK(n)   ((!(((n) + 1900) % 400) || (!(((n) + 1900) % 4) && (((n) + 1900) % 100))) != 0)
 
#define TM_WRAP(a, b, m)   ((a) = ((a) < 0 ) ? ((b)--, (a) + (m)) : (a))
 

Functions

int dl_doy2md (int year, int jday, int *month, int *mday)
 Compute the month and day-of-month from day-of-year. More...
 
int dl_md2doy (int year, int month, int mday, int *jday)
 Compute the day-of-year from year, month and day-of-month. More...
 
char * dl_dltime2isotimestr (dltime_t dltime, char *isotimestr, int8_t subseconds)
 Generate an ISO time string from a dltime_t. More...
 
char * dl_dltime2mdtimestr (dltime_t dltime, char *mdtimestr, int8_t subseconds)
 Generate an time string in month-day format from a dltime_t. More...
 
char * dl_dltime2seedtimestr (dltime_t dltime, char *seedtimestr, int8_t subseconds)
 Generate an time string in SEED format from a dltime_t. More...
 
dltime_t dl_time2dltime (int year, int day, int hour, int min, int sec, int usec)
 Convert specified time values to a dltime_t value. More...
 
dltime_t dl_seedtimestr2dltime (char *seedtimestr)
 Convert a SEED time string to a dltime_t value. More...
 
dltime_t dl_timestr2dltime (char *timestr)
 Convert a time string to a dltime_t value. More...
 

Variables

const char pivotal_gmtime_r_stamp_ld []
 

Detailed Description

General time utility routines and routines for dealing with libdali time values of dltime_t type.

Author
Chad Trabant, IRIS Data Management Center

modified: 2011.003

Function Documentation

char* dl_dltime2isotimestr ( dltime_t  dltime,
char *  isotimestr,
int8_t  subseconds 
)

Generate an ISO time string from a dltime_t.

Build a time string in ISO recommended format from a high precision epoch time, dltime_t, value.

The provided isostimestr must have enough room for the resulting time string of 27 characters, i.e. '2001-07-29T12:38:00.000000' + NULL.

The 'subseconds' flag controls whenther the sub second portion of the time is included or not.

Parameters
dltimeThe dltime_t time value
isotimestrReturned ISO time string, must have room for 27 characters
subsecondsFlag to control the inclusion of subseconds
Returns
A pointer to the resulting string or NULL on error.
char* dl_dltime2mdtimestr ( dltime_t  dltime,
char *  mdtimestr,
int8_t  subseconds 
)

Generate an time string in month-day format from a dltime_t.

Build a time string in month-day format from a high precision epoch time.

The provided mdtimestr must have enough room for the resulting time string of 27 characters, i.e. '2001-07-29 12:38:00.000000' + NULL.

The 'subseconds' flag controls whenther the sub second portion of the time is included or not.

Parameters
dltimeThe dltime_t time value
mdtimestrReturned time string, must have room for 27 characters
subsecondsFlag to control the inclusion of subseconds
Returns
A pointer to the resulting string or NULL on error.
char* dl_dltime2seedtimestr ( dltime_t  dltime,
char *  seedtimestr,
int8_t  subseconds 
)

Generate an time string in SEED format from a dltime_t.

Build a SEED (day-of-year) time string from a high precision epoch time.

The provided seedtimestr must have enough room for the resulting time string of 25 characters, i.e. '2001,195,12:38:00.000000
'.

The 'subseconds' flag controls whenther the sub second portion of the time is included or not.

Parameters
dltimeThe dltime_t time value
seedtimestrReturned time string, must have room for 25 characters
subsecondsFlag to control the inclusion of subseconds
Returns
A pointer to the resulting string or NULL on error.
int dl_doy2md ( int  year,
int  jday,
int *  month,
int *  mday 
)

Compute the month and day-of-month from day-of-year.

Compute the month and day-of-month from a year and day-of-year.

Year is expected to be in the range 1900-2100, jday is expected to be in the range 1-366, month will be in the range 1-12 and mday will be in the range 1-31.

Parameters
yearYear (1900 - 2100)
jdayDay-of-year, "Julian" day (1 - 366)
monthReturned month (1 - 12)
mdayReturned day-of-month (1 - 31)
Returns
0 on success and -1 on error.
int dl_md2doy ( int  year,
int  month,
int  mday,
int *  jday 
)

Compute the day-of-year from year, month and day-of-month.

Compute the day-of-year from a year, month and day-of-month.

Year is expected to be in the range 1900-2100, month is expected to be in the range 1-12, mday is expected to be in the range 1-31 and jday will be in the range 1-366.

Parameters
yearYear (1900 - 2100)
monthMonth (1 - 12)
mdayDay-of-month (1 - 31)
jdayReturned day-of-year, "Julian" day (1 - 366)
Returns
0 on success and -1 on error.
dltime_t dl_seedtimestr2dltime ( char *  seedtimestr)

Convert a SEED time string to a dltime_t value.

Convert a SEED time string to a high precision epoch time. SEED time format is "YYYY[,DDD,HH,MM,SS.FFFFFF]", the delimiter can be a comma [,], colon [:] or period [.] except for the fractional seconds which must start with a period [.].

The time string can be "short" in which case the omitted values are assumed to be zero (with the exception of DDD which is assumed to be 1): "YYYY,DDD,HH" assumes MM, SS and FFFF are 0. The year is required, otherwise there wouldn't be much for a date.

Ranges are checked for each time value.

Parameters
seedtimestrSEED time string to convert
Returns
dltime_t time value on success and DLTERROR on error.
dltime_t dl_time2dltime ( int  year,
int  day,
int  hour,
int  min,
int  sec,
int  usec 
)

Convert specified time values to a dltime_t value.

Convert specified time values to a high precision epoch time, a dltime_t value. The routine will range check all the input parameters.

Parameters
yearYear (1900 - 2100)
dayDay (1 - 366)
hourHour (0 - 23)
minMinute (0 - 59)
secSecond (0 - 60)
usecMicrosecond (0 - 999999)
Returns
dltime_t time value on success and DLTERROR on error.
dltime_t dl_timestr2dltime ( char *  timestr)

Convert a time string to a dltime_t value.

Convert a generic time string to a high precision epoch time. SEED time format is "YYYY[/MM/DD HH:MM:SS.FFFF]", the delimiter can be a dash [-], slash [/], colon [:], or period [.] and between the date and time a 'T' or a space may be used. The fracttional seconds must begin with a period [.].

The time string can be "short" in which case the omitted values are assumed to be zero (with the exception of month and day which are assumed to be 1): "YYYY/MM/DD" assumes HH, MM, SS and FFFF are 0. The year is required, otherwise there wouldn't be much for a date.

Ranges are checked for each time value.

Parameters
timestrTime string to convert
Returns
dltime_t time value on success and DLTERROR on error.

Variable Documentation

const char pivotal_gmtime_r_stamp_ld[]
Initial value:
=
"pivotal_gmtime_r. Copyright (C) 2009 Paul Sheer. Terms and "
"conditions apply. Visit http://2038bug.com/ for more info."