Changeset 4602 for trunk/Ohana/src/opihi/lib.data/convert.c
- Timestamp:
- Jul 23, 2005, 9:13:00 PM (21 years ago)
- File:
-
- 1 edited
-
trunk/Ohana/src/opihi/lib.data/convert.c (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Ohana/src/opihi/lib.data/convert.c
r2598 r4602 1 1 # include "convert.h" 2 # define _XOPEN_SOURCE /* glibc2 needs this */ 3 # include <time.h> 4 5 char *strptime(const char *s, const char *format, struct tm *tm); 6 2 7 3 8 int hh_hms (double hh, int *hr, int *mn, double *sc) { … … 160 165 161 166 return (status); 167 } 168 169 /***** convert 00:00:00 or 00:00 to 0 - 86400 ****/ 170 int hms_to_sec (char *string, time_t *second) { 171 172 char *p; 173 struct tm time; 174 175 p = strptime (string, "%H:%M:%S", &time); 176 if (p != NULL) goto valid; 177 178 p = strptime (string, "%H:%M", &time); 179 if (p != NULL) goto valid; 180 181 return (FALSE); 182 183 valid: 184 if (*p) return (FALSE); 185 *second = time.tm_hour*3600 + time.tm_min*60 + time.tm_sec; 186 return (TRUE); 187 } 188 189 /***** convert Mon[@00:00:00] or 00:00 to 0 - 86400*7 ****/ 190 int day_to_sec (char *string, time_t *second) { 191 192 char *p; 193 struct tm time; 194 195 bzero (&time, sizeof(time)); 196 p = strptime (string, "%A@%H:%M:%S", &time); 197 if (p != NULL) goto valid; 198 199 p = strptime (string, "%A@%H:%M", &time); 200 if (p != NULL) goto valid; 201 202 p = strptime (string, "%A@%H", &time); 203 if (p != NULL) goto valid; 204 205 p = strptime (string, "%A", &time); 206 if (p != NULL) goto valid; 207 208 return (FALSE); 209 210 valid: 211 if (*p) return (FALSE); 212 *second = time.tm_wday*86400 + time.tm_hour*3600 + time.tm_min*60 + time.tm_sec; 213 return (TRUE); 162 214 } 163 215
Note:
See TracChangeset
for help on using the changeset viewer.
