+static time_t
+parse_time(const char *value)
+{
+ int hh, mm, ss;
+ int check;
+ time_t result;
+ char c;
+ struct tm *tm;
+
+ if (sscanf(value, "%d:%d:%d%c", &hh, &mm, &ss, &c) != 3) {
+ if (sscanf(value, "%02d%02d%02d%c", &hh, &mm, &ss, &c) != 3) {
+ usage();
+ }
+ }
+
+ if ((hh < 0) || (hh >= 24) ||
+ (mm < 0) || (mm >= 60) ||
+ (ss < 0) || (ss >= 60)) {
+ usage();
+ }
+
+ /* adjust so that the localtime in the main loop will give usable time */
+ result = (hh * 3600) + ((mm * 60) + ss);
+ for (check = 0; check < 24; ++check) {
+ tm = localtime(&result);
+ if (tm->tm_hour == hh)
+ break;
+ result += 3600;
+ }
+
+ if (tm->tm_hour != hh) {
+ fprintf(stderr, "Cannot find local time for %s!\n", value);
+ usage();
+ }
+ return result;
+}
+