7 /* time value conversion
9 /* #include <conv_time.h>
11 /* int conv_time(strval, timval, def_unit);
12 /* const char *strval;
16 /* conv_time() converts a numerical time value with optional
17 /* one-letter suffix that specifies an explicit time unit: s
18 /* (seconds), m (minutes), h (hours), d (days) or w (weeks).
19 /* Internally, time is represented in seconds.
27 /* The default time unit suffix character.
29 /* The result value is non-zero in case of success, zero in
30 /* case of a bad time value or a bad time unit suffix.
34 /* The Secure Mailer license must be distributed with this software.
37 /* IBM T.J. Watson Research
39 /* Yorktown Heights, NY 10598, USA
45 #include <limits.h> /* INT_MAX */
46 #include <stdio.h> /* sscanf() */
48 /* Utility library. */
54 #include <conv_time.h>
57 #define HOUR (60 * MINUTE)
58 #define DAY (24 * HOUR)
59 #define WEEK (7 * DAY)
61 /* conv_time - convert time value */
63 int conv_time(const char *strval
, int *timval
, int def_unit
)
69 switch (sscanf(strval
, "%d%c%c", &intval
, &unit
, &junk
)) {
78 if (intval
< INT_MAX
/ WEEK
) {
79 *timval
= intval
* WEEK
;
85 if (intval
< INT_MAX
/ DAY
) {
86 *timval
= intval
* DAY
;
92 if (intval
< INT_MAX
/ HOUR
) {
93 *timval
= intval
* HOUR
;
99 if (intval
< INT_MAX
/ MINUTE
) {
100 *timval
= intval
* MINUTE
;