time_utils.h

Go to the documentation of this file.
00001 #ifndef __time_utils_h__
00002 #define __time_utils_h__
00003 
00004 #include <ctype.h>
00005 #include <time.h>
00006 
00007 #define seenYear seen.tm_year
00008 #define seenMonth seen.tm_mon
00009 #define seenDay seen.tm_mday
00010 #define seenHour seen.tm_hour
00011 #define seenMin seen.tm_min
00012 #define seenSec seen.tm_sec
00013 
00014 #define SET_TODAY_TO_TM(tm_name)        \
00015   (tm_name).tm_year = now_tm.tm_year;       \
00016   (tm_name).tm_mon = now_tm.tm_mon;       \
00017   (tm_name).tm_mday = now_tm.tm_mday;
00018 
00019 #define TODAY_SEEN_TIME_TO_TM(tm_name)        \
00020   SET_TODAY_TO_TM(tm_name);         \
00021   (tm_name).tm_hour = seenHour;         \
00022   (tm_name).tm_min = seenMin;         \
00023   (tm_name).tm_sec = seenSec;
00024 
00025 #define DEF_NOW_DAY_WITH_SEEN_TIME(tm_name)     \
00026   struct tm tm_name;            \
00027   TODAY_SEEN_TIME_TO_TM(tm_name)
00028 
00029 int int_range(int value, int minval, int maxval);
00030 
00031 #define ATOI_RANGE(s,min,max) int_range(atoi(s),min,max)
00032 
00033 #define SET_SEEN_DATE_PLUS_DAYS(rel, plus_days) \
00034   { \
00035   time_t plus_t = (rel) + (plus_days) * 24 * 60 * 60; \
00036   struct tm plus_tm; \
00037   gmtime_r(&plus_t, &plus_tm); \
00038   seenYear = plus_tm.tm_year; \
00039   seenMonth = plus_tm.tm_mon; \
00040   seenDay = plus_tm.tm_mday; \
00041   }
00042 
00043 int num_days_till_next_wday(int rel_wday, int want_wday);
00044 
00045 // Note that tm_mon range is 0 to 11.
00046 // Note that tm_year is the number of years since 1900.
00047 // "mktime" expects local time, but we have UTC in the struct.
00048 // "timegm" is a UTC equivalent of "mktime", but is a GNU extension.
00049 // SEEN_TIME_T evaluates to -1 in case of error.
00050 #define SEEN_TIME_T timegm(&seen)
00051 
00052 char* time_t_to_string(char* buf, int buflen, time_t t);
00053 
00054 #define TIME_T_GET_STR(s, t) \
00055   char s[200]; \
00056   if (!time_t_to_string(s, 200, t)) return;
00057 
00058 #endif /* __time_utils_h__ */

ContextLogger2—ContextLogger2 Logger Daemon Internals—Generated on Mon May 2 13:49:56 2011 by Doxygen 1.6.1