Hi coreutils people!

Guessing timezones with date is dangerous.
What is the time in the US, say, Mountain area?

$ env TZ=US/Mountain date
Mon Sep 19 11:51:28 MDT 2005
--> correct.

$ env TZ=MST date
Mon Sep 19 10:51:58 MST 2005
--> correct.

Aha, difference between MDT and MST is one hour. 
Let us check that with the abbreviated name, as seen above:

$ env TZ=MDT date
Mon Sep 19 17:52:53 MDT 2005
--> wrong.

Oops, now difference is 7 hours ...
The problem here is, that MDT is an unknown timezone on my machine.
Date silently defaults back to GMT, but it keeps the label 'MDT'.

The first bug here may be that env TZ=US/Mountain date prints a timezone
name that it cannot use as its own input. I don't want to fix that now.

The second and IMHO more serious bug is that invalid input is not 
recognized as such, and thus very misleading output is generated.

Please find attached a trivial patch that checks for unknown 
timezones and prints a warning. I should also change the printed label 
in that case, but I don't see an easy way to do that.

        thanks,
                Jw.

-- 
 o \  Juergen Weigert  paint it green! __/ _=======.=======_
<V> | [EMAIL PROTECTED]       wide open suse_/        _---|____________\/
 \  | 0911 74053-508         (tm)__/          (____/            /\
(/) | __________________________/             _/ \_ vim:set sw=2 wm=8
--- ./coreutils/src/date.c.orig 2005-09-16 10:08:00.000000000 +0200
+++ ./coreutils/src/date.c      2005-09-19 19:02:30.378609502 +0200
@@ -271,6 +271,15 @@
        }
     }
 
+#ifdef HAVE_TZSET
+  /* Cannot use HAVE_TZNAME here. sigh, [EMAIL PROTECTED] */
+  extern char *tzname[2];
+  if (!tzname[1][0])
+    {
+      error (0, 0, _("invalid timezone %s, using default"), tzname[0]);
+    }
+#endif
+
   line = NULL;
   buflen = 0;
   ok = true;
_______________________________________________
Bug-coreutils mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/bug-coreutils

Reply via email to