lib/eggdrop/timeutil.c File Reference

#include <eggdrop/eggdrop.h>

Go to the source code of this file.

Functions

char * duration_to_string (time_t difftime)
time_t parse_expire_string (char *s)

Variables

static const char rcsid [] = "$Id: timeutil.c,v 1.5 2004-10-17 05:14:06 stdarg Exp $"


Function Documentation

char* duration_to_string ( time_t  difftime  ) 

Definition at line 29 of file timeutil.c.

References hours.

00030 {
00031   static char durstring[64];
00032   time_t days, hours, mins;
00033   int len;
00034 
00035   *durstring = '\0';
00036   days = difftime/86400;
00037   difftime -= days*86400;
00038   hours = difftime/3600;
00039   difftime -= hours*3600;
00040   mins = difftime/60;
00041 
00042   if (days)
00043     snprintf(durstring, sizeof(durstring), "%ld %s", days, days==1?"day":"days");
00044   if (hours) {
00045     len = strlen(durstring);
00046     snprintf(&durstring[len], sizeof(durstring) - len, "%s%ld %s",
00047       !len?"":mins?", ":"and ", hours, hours==1?"hour":"hours");
00048   }
00049   if (mins) {
00050     len = strlen(durstring);
00051     snprintf(&durstring[len], sizeof(durstring) - len, "%s%ld %s",
00052       len?" and ":"", mins, mins==1?"minute":"minutes");
00053   }
00054 
00055   return strlen(durstring)?durstring:"less than minute";
00056 }

time_t parse_expire_string ( char *  s  ) 

Definition at line 59 of file timeutil.c.

References NULL.

00060 {
00061   time_t tmp, exptime = 0;
00062   char *endptr = NULL;
00063 
00064   /* No need to:
00065      if (!s || *s!='%') return 0;
00066      caller already made sure
00067   */
00068   s++;
00069   while (*s) {
00070     tmp = strtoul(s, &endptr, 10);
00071     switch(tolower(*endptr)) {
00072       case 'd':
00073         if (tmp > 365)
00074         tmp = 365;
00075         exptime += 86400 * tmp;
00076         break;
00077       case 'h':
00078         if (tmp > 8760)
00079         tmp = 8760;
00080         exptime += 3600 * tmp;
00081         break;
00082       case 'm':
00083         if (tmp > 525600)
00084         tmp = 525600;
00085         exptime += 60 * tmp;
00086         break;
00087       default:
00088         return 0;
00089     }
00090     s = endptr+1;
00091   }
00092   return exptime;
00093 }


Variable Documentation

const char rcsid[] = "$Id: timeutil.c,v 1.5 2004-10-17 05:14:06 stdarg Exp $" [static]

Definition at line 21 of file timeutil.c.


Generated on Sun Nov 30 18:43:35 2008 for eggdrop1.9 by  doxygen 1.5.6