Have zdump output gmtoff= even on platforms lacking TM_GMTOFF. · eggert/tz@40b395e (original) (raw)
`@@ -851,19 +851,54 @@ delta(struct tm * newp, struct tm *oldp)
`
851
851
`return result;
`
852
852
`}
`
853
853
``
``
854
`+
/* Return A->tm_yday, adjusted to compare it fairly to B->tm_yday.
`
``
855
`+
Assume A and B differ by at most one year. */
`
``
856
`+
static int
`
``
857
`+
adjusted_yday(struct tm const *a, struct tm const *b)
`
``
858
`+
{
`
``
859
`+
int yday = a->tm_yday;
`
``
860
`+
if (b->tm_year < a->tm_year)
`
``
861
`+
yday += 365 + isleap_sum(b->tm_year, TM_YEAR_BASE);
`
``
862
`+
return yday;
`
``
863
`+
}
`
``
864
+
``
865
`+
/* If A is the broken-down local time and B the broken-down UTC for
`
``
866
`+
the same instant, return A's UTC offset in seconds, where positive
`
``
867
`+
offsets are east of Greenwich. On failure, return LONG_MIN. */
`
``
868
`+
static long
`
``
869
`+
gmtoff(struct tm const *a, struct tm const *b)
`
``
870
`+
{
`
``
871
`+
#ifdef TM_GMTOFF
`
``
872
`+
return a->TM_GMTOFF;
`
``
873
`+
#else
`
``
874
`+
if (! b)
`
``
875
`+
return LONG_MIN;
`
``
876
`+
else {
`
``
877
`+
int ayday = adjusted_yday(a, b);
`
``
878
`+
int byday = adjusted_yday(b, a);
`
``
879
`+
int days = ayday - byday;
`
``
880
`+
long hours = a->tm_hour - b->tm_hour + 24 * days;
`
``
881
`+
long minutes = a->tm_min - b->tm_min + 60 * hours;
`
``
882
`+
long seconds = a->tm_sec - b->tm_sec + 60 * minutes;
`
``
883
`+
return seconds;
`
``
884
`+
}
`
``
885
`+
#endif
`
``
886
`+
}
`
``
887
+
854
888
`static void
`
855
889
`show(timezone_t tz, char *zone, time_t t, bool v)
`
856
890
`{
`
857
891
` register struct tm * tmp;
`
858
``
`-
struct tm tm;
`
``
892
`+
register struct tm * gmtmp;
`
``
893
`+
struct tm tm, gmtm;
`
859
894
``
860
895
`printf("%-*s ", longest, zone);
`
861
896
`if (v) {
`
862
``
`-
tmp = my_gmtime_r(&t, &tm);
`
863
``
`-
if (tmp == NULL) {
`
``
897
`+
gmtmp = my_gmtime_r(&t, &gmtm);
`
``
898
`+
if (gmtmp == NULL) {
`
864
899
`printf(tformat(), t);
`
865
900
` } else {
`
866
``
`-
dumptime(tmp);
`
``
901
`+
dumptime(gmtmp);
`
867
902
`printf(" UT");
`
868
903
` }
`
869
904
`printf(" = ");
`
`@@ -874,10 +909,10 @@ show(timezone_t tz, char *zone, time_t t, bool v)
`
874
909
`if (*abbr(tmp) != '\0')
`
875
910
`printf(" %s", abbr(tmp));
`
876
911
`if (v) {
`
``
912
`+
long off = gmtoff(tmp, gmtmp);
`
877
913
`printf(" isdst=%d", tmp->tm_isdst);
`
878
``
`-
#ifdef TM_GMTOFF
`
879
``
`-
printf(" gmtoff=%ld", tmp->TM_GMTOFF);
`
880
``
`-
#endif /* defined TM_GMTOFF */
`
``
914
`+
if (off != LONG_MIN)
`
``
915
`+
printf(" gmtoff=%ld", off);
`
881
916
` }
`
882
917
` }
`
883
918
`printf("\n");
`