]> diplodocus.org Git - nmh/blobdiff - sbr/datetime.c
sizeof char is always 1, so don't bother to divide by it.
[nmh] / sbr / datetime.c
index 8478414e4a0feb2cdd52b2079bc4f765abe23d2c..a5f6c77b02bd02eed1197afd05dd831650551100 100644 (file)
@@ -1,5 +1,4 @@
-/*
- * datetime.c -- functions for manipulating RFC 5545 date-time values
+/* datetime.c -- functions for manipulating RFC 5545 date-time values
  *
  * This code is Copyright (c) 2014, by the authors of nmh.
  * See the COPYRIGHT file in the root directory of the nmh
@@ -11,6 +10,7 @@
 #include <h/fmt_scan.h>
 #include "h/tws.h"
 #include "h/utils.h"
+#include "unquote.h"
 
 /*
  * This doesn't try to support all of the myriad date-time formats
@@ -75,7 +75,7 @@ parse_datetime (const char *datetime, const char *zone, int dst,
     if (items_matched == 7) {
         /* The 'Z' must be capital according to RFC 5545 Sec. 3.3.5. */
         if (utc_indicator != 'Z') {
-            advise (NULL, "%s has invalid timezone indicator of 0x%x",
+            inform("%s has invalid timezone indicator of 0x%x",
                     datetime, utc_indicator);
             return NOTOK;
         }
@@ -96,7 +96,8 @@ parse_datetime (const char *datetime, const char *zone, int dst,
         set_dotw (tws);
         /* set_dotw() sets TW_SIMP.  Replace that with TW_SEXP so that
            dasctime() outputs the dotw before the date instead of after. */
-        tws->tw_flags &= ~TW_SDAY, tws->tw_flags |= TW_SEXP;
+        tws->tw_flags &= ~TW_SDAY;
+        tws->tw_flags |= TW_SEXP;
 
         /* For the call to dmktime():
            - don't need tw_yday
@@ -143,9 +144,9 @@ parse_datetime (const char *datetime, const char *zone, int dst,
         }
 
         return OK;
-    } else {
-        return NOTOK;
     }
+
+    return NOTOK;
 }
 
 tzdesc_t
@@ -170,14 +171,14 @@ load_timezones (const contentline *clines) {
                 if (in_standard) { in_standard = 0; }
                 else if (in_daylight) { in_daylight = 0; }
                 if (parse_datetime (params->dtstart, params->offsetfrom,
-                                    in_daylight ? 1 : 0,
+                                    in_daylight,
                                     &tws) == OK) {
                     if (tws.tw_year >= 1970) {
                         /* dmktime() falls apart for, e.g., the year 1601. */
                         params->start_dt = tws.tw_clock;
                     }
                 } else {
-                    advise (NULL, "failed to parse start time %s for %s",
+                    inform("failed to parse start time %s for %s",
                             params->dtstart,
                             in_standard ? "standard" : "daylight");
                     return NULL;
@@ -321,9 +322,8 @@ rrule_clock (const char *rrule, const char *starttime, const char *zone,
 
 fail:
     if (clock == 0) {
-        admonish (NULL,
-                  "Unsupported RRULE format: %s, assume local timezone",
-                  rrule);
+        inform("Unsupported RRULE format: %s, assume local timezone, continuing...",
+           rrule);
     }
 
     return clock;
@@ -359,10 +359,9 @@ format_datetime (tzdesc_t timezones, const contentline *node) {
            Form #2: DATE WITH UTC TIME */
         if (parse_datetime (node->value, NULL, 0, &tws[0]) == OK) {
             return strdup (dasctime (&tws[0], 0));
-        } else {
-            advise (NULL, "unable to parse datetime %s", node->value);
-            return NULL;
         }
+        inform("unable to parse datetime %s", node->value);
+        return NULL;
     }
 
     /*
@@ -372,7 +371,7 @@ format_datetime (tzdesc_t timezones, const contentline *node) {
 
     /* Find the corresponding tzdesc. */
     for (tz = timezones; dt_timezone && tz; tz = tz->next) {
-        /* Property parameter values are case insenstive (RFC 5545
+        /* Property parameter values are case insensitive (RFC 5545
            Sec. 2) and time zone identifiers are property parameters
            (RFC 5545 Sec. 3.8.2.4), though it would seem odd to use
            different case in the same file for identifiers that are
@@ -383,7 +382,7 @@ format_datetime (tzdesc_t timezones, const contentline *node) {
     if (tz) {
         free(dt_timezone);
     } else {
-        advise (NULL, "did not find VTIMEZONE section for %s", dt_timezone);
+        inform("did not find VTIMEZONE section for %s", dt_timezone);
         free(dt_timezone);
         return NULL;
     }
@@ -425,7 +424,7 @@ format_datetime (tzdesc_t timezones, const contentline *node) {
         }
 
         if (transition[0] < transition[1]) {
-            advise (NULL, "format_datetime() requires that daylight "
+            inform("format_datetime() requires that daylight "
                     "saving time transition precede standard time "
                     "transition");
             return NULL;
@@ -435,7 +434,7 @@ format_datetime (tzdesc_t timezones, const contentline *node) {
                             0, &tws[0]) == OK) {
             dt[0] = tws[0].tw_clock;
         } else {
-            advise (NULL, "unable to parse datetime %s", node->value);
+            inform("unable to parse datetime %s", node->value);
             return NULL;
         }
 
@@ -448,19 +447,19 @@ format_datetime (tzdesc_t timezones, const contentline *node) {
                                     &tws[1]) == OK) {
                     dt[1] = tws[1].tw_clock;
                 } else {
-                    advise (NULL, "unable to parse datetime %s",
+                    inform("unable to parse datetime %s",
                             node->value);
                     return NULL;
                 }
 
-                dst = dt[1] > transition[0]  ?  0  :  1;
+                dst = dt[1] <= transition[0];
             }
         }
 
         if (dst) {
             if (tz->daylight_params.start_dt > 0  &&
                 dt[dst] < tz->daylight_params.start_dt) {
-                advise (NULL, "date-time of %s is before VTIMEZONE start "
+                inform("date-time of %s is before VTIMEZONE start "
                         "of %s", node->value,
                         tz->daylight_params.dtstart);
                 return NULL;
@@ -468,7 +467,7 @@ format_datetime (tzdesc_t timezones, const contentline *node) {
         } else {
             if (tz->standard_params.start_dt > 0  &&
                 dt[dst] < tz->standard_params.start_dt) {
-                advise (NULL, "date-time of %s is before VTIMEZONE start "
+                inform("date-time of %s is before VTIMEZONE start "
                         "of %s", node->value,
                         tz->standard_params.dtstart);
                 return NULL;
@@ -476,12 +475,12 @@ format_datetime (tzdesc_t timezones, const contentline *node) {
         }
     } else {
         if (! tp_std) {
-            advise (NULL, "unsupported date-time format: %s",
+            inform("unsupported date-time format: %s",
                     tz->standard_params.dtstart);
             return NULL;
         }
         if (! tp_dt) {
-            advise (NULL, "unsupported date-time format: %s", node->value);
+            inform("unsupported date-time format: %s", node->value);
             return NULL;
         }
     }