Renamed DSTXXX as ADJUST_NUMERIC_ONLY_TZ_OFFSETS_WRT_DST and added an
[mmh] / sbr / dtimep.lex
index 4f01980..c36844d 100644 (file)
@@ -86,8 +86,10 @@ static int month_map[] = {
 };
 
 /*
- * Same trick for day-of-week using the hash function
- *  (c1 & 7) + (c2 & 4)
+ * Lookup table for day-of-week using the same hash trick as for above name-of-
+ * month table, but using the first and second character, not second and third.
+ *
+ * Compute index into table using: (day_name[0] & 7) + (day_name[1] & 4)
  */
 static int day_map[] = {
        0,
@@ -115,8 +117,7 @@ static int day_map[] = {
  */
 
 #define INIT()       { cp = yytext;} 
-#define SETWDAY()    { cp++; \
-                       tw.tw_wday= day_map[(cp[0] & 7) + (cp[1] & 4)]; \
+#define SETWDAY()    { tw.tw_wday= day_map[(cp[0] & 7) + (cp[1] & 4)]; \
                        tw.tw_flags &= ~TW_SDAY; tw.tw_flags |= TW_SEXP; \
                        SKIPA(); }
 #define SETMON()     { cp++; \
@@ -152,6 +153,34 @@ static int day_map[] = {
                        --cp; }
 #define SKIPTOSP()   { while ( !isspace(*cp++) ) ; \
                        --cp; }
+
+#ifdef ADJUST_NUMERIC_ONLY_TZ_OFFSETS_WRT_DST
+# ifdef TIME_WITH_SYS_TIME
+#  include <sys/time.h>
+#  include <time.h>
+# else
+#  ifdef HAVE_SYS_TIME_H
+#   include <sys/time.h>
+#  else
+#   include <time.h>
+#  endif
+# endif
+
+static void
+zonehack (struct tws *tw)
+{
+    register struct tm *tm;
+
+    if (dmktime (tw) == (time_t) -1)
+       return;
+
+    tm = localtime (&tw->tw_clock);
+    if (tm->tm_isdst) {
+       tw->tw_flags |= TW_DST;
+       tw->tw_zone -= 60;
+    }
+}
+#endif /* ADJUST_NUMERIC_ONLY_TZ_OFFSETS_WRT_DST */
 %}
 
 sun    ([Ss]un(day)?)
@@ -326,11 +355,17 @@ d [0-9]
                                     INIT();
                                     SKIPTOD();
                                     SETZONE(atoi(cp));
+#ifdef ADJUST_NUMERIC_ONLY_TZ_OFFSETS_WRT_DST
+                                   zonehack (&tw);
+#endif /* ADJUST_NUMERIC_ONLY_TZ_OFFSETS_WRT_DST */
                                     }
 "-"{D}{d}{d}                                  {
                                     INIT();
                                     SKIPTOD();
                                     SETZONE(-atoi(cp));
+#ifdef ADJUST_NUMERIC_ONLY_TZ_OFFSETS_WRT_DST
+                                   zonehack (&tw);
+#endif /* ADJUST_NUMERIC_ONLY_TZ_OFFSETS_WRT_DST */
                                     }
 "-"?("ut"|"UT")                            INIT(); SETZONE(0);
 "-"?("gmt"|"GMT")                  INIT(); SETZONE(0);