threads / patch / 872

patchFix cogito handling of timezones

Subject: [PATCH] Fix cogito handling of timezones

## tl;dr

3 messages between Jun 9, 2005 and Jun 9, 2005. Diffs are folded; open one to read it.

replies: 2people: 2as markdown or json

Frank Sorenson· Jun 9, 2005, 03:40 UTC · lore
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Current cogito behavior treats the timezone offset as if it's decimal, but most zone offsets begin with a 0. As a result, the computation in cg-Xlib uses the zone offset as an octal number. -0700 looks like 4 1/2 hours offset, rather than 7, and -0800 is an invalid octal number.

This patch fixes the behavior to strip off leading 0s. It's ugly, but it should produce the right values until someone with better bash scripting skills than I can fix it.

Signed-off-by: Frank Sorenson <frank@tuxrocks.com>
Show changes to cg-Xlib +8 −4
diff --git a/cg-Xlib b/cg-Xlib
- --- a/cg-Xlib
+++ b/cg-Xlib
@@ -6,6 +6,8 @@
 # This file provides a library containing common code shared with all the
 # Cogito programs.
 
+shopt -s extglob
+
 _cg_cmd=${0##*/}
 
 _git=${GIT_DIR:-.git}
@@ -51,8 +53,12 @@ showdate () {
 	[ "$format" ] || format=-R
 	sec=${date[0]}; tz=${date[1]}
 	if [ "$has_gnudate" ]; then
- -	        dtz=${tz/+/}
- -		lsec=$(($dtz / 100 * 3600 + $dtz % 100 * 60 + $sec))
+		sign=${tz%%[0-9]*}
+		sign=${sign:?+}
+		dtz=${tz/[+-]}
+		dtz=${dtz##*(0)}
+		dtz=${dtz:?0}
+		lsec=$(($sec + $dtz % 100 $sign $dtz / 100 * 3600))
 	        pdate="$(date -ud "1970-01-01 UTC + $lsec sec" "$format" 2>/dev/null)"
 	else
 		# FIXME: $format


Frank
- -- 
Frank Sorenson - KD7TZK
Systems Manager, Computer Science Department
Brigham Young University
frank@tuxrocks.com
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.6 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org

iD8DBQFCp7oXaI0dwg4A47wRAnOFAJ4jsaQodgxOr3gp8jMYhOxuJ98GFgCgnclC
Zd68hflXn8pV39zBF4YOlUc=
=C+hn
-----END PGP SIGNATURE-----
Petr Baudis· Jun 9, 2005, 08:29 UTC · re: Frank Sorenson · lore

Re: [PATCH] Fix cogito handling of timezones

Dear diary, on Thu, Jun 09, 2005 at 05:40:07AM CEST, I got a letter where Frank Sorenson <frank@tuxrocks.com> told me that...

Show 27 quoted lines
> Current cogito behavior treats the timezone offset as if it's decimal,
> but most zone offsets begin with a 0.  As a result, the computation
> in cg-Xlib uses the zone offset as an octal number.  -0700 looks like
> 4 1/2 hours offset, rather than 7, and -0800 is an invalid octal
> number.
> 
> This patch fixes the behavior to strip off leading 0s.  It's ugly,
> but it should produce the right values until someone with better
> bash scripting skills than I can fix it.
> 
> Signed-off-by: Frank Sorenson <frank@tuxrocks.com>
> 
> diff --git a/cg-Xlib b/cg-Xlib
> --- a/cg-Xlib
> +++ b/cg-Xlib
> @@ -51,8 +53,12 @@ showdate () {
>  	[ "$format" ] || format=-R
>  	sec=${date[0]}; tz=${date[1]}
>  	if [ "$has_gnudate" ]; then
> -	        dtz=${tz/+/}
> -		lsec=$(($dtz / 100 * 3600 + $dtz % 100 * 60 + $sec))
> +		sign=${tz%%[0-9]*}
> +		sign=${sign:?+}
> +		dtz=${tz/[+-]}
> +		dtz=${dtz##*(0)}
> +		dtz=${dtz:?0}
> +		lsec=$(($sec + $dtz % 100 $sign $dtz / 100 * 3600))

It looks ok, but shouldn't this be + lsec=$(($sec + $dtz % 100 * 60 $sign $dtz / 100 * 3600))

-- 
				Petr "Pasky" Baudis
Stuff: http://pasky.or.cz/
<Espy> be careful, some twit might quote you out of context..
Frank Sorenson· Jun 9, 2005, 14:20 UTC · re: Petr Baudis · lore

Re: [PATCH] Fix cogito handling of timezones

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Petr Baudis wrote:
> It looks ok, but shouldn't this be
> +		lsec=$(($sec + $dtz % 100 * 60 $sign $dtz / 100 * 3600))

Ah, yes, of course. I see that Dan Holmsand has also sent a patch (3/6) to fix this. I haven't tested his very much, but it looks like a cleaner and more comprehensive solution. Sigh.

Frank
- -- 
Frank Sorenson - KD7TZK
Systems Manager, Computer Science Department
Brigham Young University
frank@tuxrocks.com
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.6 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org

iD8DBQFCqFAtaI0dwg4A47wRAlaEAJ0Ui38Yrwp7r0QUseI5/7n4kbnRaACfZBv0 M5TClhJuvD2y7fz/Fm9pNes= =SOdU -----END PGP SIGNATURE-----

← back to recent threads