time_utils.c

Go to the documentation of this file.
00001 #include "time_utils.h"
00002 
00003 int int_range(int value, int min, int max)
00004 {
00005   return (((value) < (min)) ? (min) : (((value) > (max)) ? (max) : (value)));
00006 }
00007 
00008 // Returns NULL on error, otherwise "buf".
00009 char* time_t_to_string(char* buf, int buflen, time_t t)
00010 {
00011   struct tm result_tm;
00012   if (!gmtime_r(&t, &result_tm)) {
00013     return NULL; // error
00014   }
00015   if (strftime(buf, buflen, "%F %T", &result_tm) == 0) {
00016     // With this format string, 0 size output is an error.
00017     return NULL;
00018   }
00019   return buf;
00020 }
00021 
00022 int num_days_till_next_wday(int rel_wday, int want_wday)
00023 {
00024   return ((want_wday > rel_wday) ? 
00025     (want_wday - rel_wday) : 
00026     (want_wday - rel_wday + 7));
00027 }

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