- int hours, mins;
- static char buffer[10];
-
- if (offset < 0) {
- mins = -((-offset) % 60);
- hours = -((-offset) / 60);
- } else {
- mins = offset % 60;
- hours = offset / 60;
- }
+ static char buffer[sizeof "+3579139459"]; /* 2,147,483,648 / 60 = 35,791,394 */
+ bool pos;
+ unsigned os, hours, mins;
+
+ pos = offset >= 0;
+ os = pos ? offset : ~offset + 1; /* abs(3) undefined on INT_MIN. */
+ hours = os / 60;
+ mins = os % 60;
+
+ if (flags & TW_DST) /* Shift towards +infinity. */
+ hours += pos ? 1 : -1;
+
+ snprintf(buffer, sizeof(buffer), "%c%02u%02u",
+ pos ? '+' : '-', hours, mins);