diff --git a/zdump.c b/zdump.c index 16e73ae..42b7027 100644 --- a/zdump.c +++ b/zdump.c @@ -660,6 +660,15 @@ yeartot(intmax_t y) return t; } + +static void +printtm(char const *name, struct tm const *tm, char const *abbr) +{ + printf(" %s={%d-%.3dT%.2d:%.2d:%.2d dst=%d abbr='%s'}", + name, tm->tm_year + 1900, tm->tm_yday + 1, + tm->tm_hour, tm->tm_min, tm->tm_sec, tm->tm_isdst, abbr); +} + /* Search for a discontinuity in timezone TZ with name NAME, in the timestamps ranging from LOT (with broken-down time LOTMP if nonnull) through HIT. LOT and HIT disagree about some aspect of @@ -693,9 +702,50 @@ hunt(timezone_t tz, char *name, time_t lot, struct tm *lotmp, time_t hit, - ((lot % 2 + hit % 2) < 0) + ((lot % 2 + hit % 2) == 2) + hit / 2); + + time_t diff = hit - lot, altt; + if ((diff < 2) != (t == lot)) { + printf("TRACING: bad break - lot="); printf(tformat(), lot); + printf(" t="); printf(tformat(), t); + printf(" hit="); printf(tformat(), hit); + printf(" diff="); printf(tformat(), diff); + printf("\n"); + } + if (t == lot) break; + + altt = lot; + altt += diff / 2; + if (altt <= lot) + ++altt; + else if (altt >= hit) + --altt; + if (t != altt) { + printf("TRACING: bad t - lot="); printf(tformat(), lot); + printf(" t="); printf(tformat(), t); + printf(" hit="); printf(tformat(), hit); + printf(" altt="); printf(tformat(), altt); + printf("\n"); + } + tm_ok = my_localtime_rz(tz, &t, &tm) != NULL; + + printf("TRACING: lotm_ok=%d tm_ok=%d only_ok=%d lot=", + lotm_ok, tm_ok, only_ok); + printf(tformat(), lot); + printf(" t="); + printf(tformat(), t); + if (lotm_ok == tm_ok && !only_ok) { + printtm("tm", &tm, abbr(&tm)); + printtm("lotm", &lotm, ab); + printf(" delta=%jd t-lot=", delta(&tm, &lotm)); + printf(tformat(), t - lot); + } + printf(" hit="); + printf(tformat(), hit); + printf("\n"); + if (lotm_ok == tm_ok && (only_ok || (lotm_ok && tm.tm_isdst == lotm.tm_isdst