fix sign of strftime %z output with offsets <1 hour west of UTC
authorRich Felker <dalias@aerifal.cx>
Wed, 8 Aug 2018 02:15:04 +0000 (22:15 -0400)
committerRich Felker <dalias@aerifal.cx>
Wed, 8 Aug 2018 02:15:04 +0000 (22:15 -0400)
the sign character produced came from the sign of tm_gmtoff/3600 as an
integer division, which is zero for negative offsets smaller in
magnitude than 3600. instead of printing the hours and minutes as
separate fields, print them as a single value of the form
hours*100+minutes, which naturally has the correct sign.

src/time/strftime.c

index 0a2569706db4ba73fe16fc3cdbb12d51c4751b8d..d3f2add92da2a7c4f26b451e591f971ae7eb808f 100644 (file)
@@ -181,9 +181,8 @@ const char *__strftime_fmt_1(char (*s)[100], size_t *l, int f, const struct tm *
                        *l = 0;
                        return "";
                }
-               *l = snprintf(*s, sizeof *s, "%+.2ld%.2d",
-                       (tm->__tm_gmtoff)/3600,
-                       abs(tm->__tm_gmtoff%3600)/60);
+               *l = snprintf(*s, sizeof *s, "%+.4ld",
+                       tm->__tm_gmtoff/3600*100 + tm->__tm_gmtoff%3600/60);
                return *s;
        case 'Z':
                if (tm->tm_isdst < 0) {