[tz] [PATCH 7/8] zic -v now shows extreme-int tm_year transitions

Paul Eggert eggert at cs.ucla.edu
Wed Mar 24 03:58:52 UTC 2021


From: Arthur David Olson <arthurdavidolson at gmail.com>

* zdump.c (main): Show transitions around cutlotime and cuthitime
if they are between out-of-range and in-range years.
---
 zdump.c | 32 ++++++++++++++++++++++++++++----
 1 file changed, 28 insertions(+), 4 deletions(-)

diff --git a/zdump.c b/zdump.c
index b006229..fbe53cd 100644
--- a/zdump.c
+++ b/zdump.c
@@ -549,6 +549,14 @@ main(int argc, char *argv[])
 			show(tz, argv[i], t, true);
 			t += SECSPERDAY;
 			show(tz, argv[i], t, true);
+			if (my_localtime_rz(tz, &t, &tm) == NULL && t < cutlotime) {
+				time_t newt = cutlotime;
+				if (my_localtime_rz(tz, &newt, &newtm) != NULL) {
+					newt = hunt(tz, argv[i], t, newt);
+					show(tz, argv[i], newt - 1, true);
+					show(tz, argv[i], newt, true);
+				}
+			}
 		}
 		if (t + 1 < cutlotime)
 		  t = cutlotime - 1;
@@ -591,6 +599,16 @@ main(int argc, char *argv[])
 		  }
 		}
 		if (! (iflag | Vflag)) {
+			time_t newt = absolute_max_time;
+			newt -= SECSPERDAY;
+			t = cuthitime;
+			if (t < newt &&
+				my_localtime_rz(tz, &t, &tm) != NULL &&
+				my_localtime_rz(tz, &newt, &newtm) == NULL) {
+				newt = hunt(tz, argv[i], t, newt);
+				show(tz, argv[i], newt - 1, true);
+				show(tz, argv[i], newt, true);
+			}
 			t = absolute_max_time;
 			t -= SECSPERDAY;
 			show(tz, argv[i], t, true);
@@ -693,10 +711,16 @@ hunt(timezone_t tz, char *name, time_t lot, time_t hit)
 static intmax_t
 delta_nonneg(struct tm *newp, struct tm *oldp)
 {
-	intmax_t oldy = oldp->tm_year;
-	int cycles = (newp->tm_year - oldy) / YEARSPERREPEAT;
-	intmax_t sec = SECSPERREPEAT, result = cycles * sec;
-	int tmy = oldp->tm_year + cycles * YEARSPERREPEAT;
+	register intmax_t	result;
+	register int		tmy;
+
+	result = 0;
+	tmy = oldp->tm_year;
+	if (newp->tm_year - tmy > YEARSPERREPEAT) {
+		intmax_t cycles = (newp->tm_year - tmy) / YEARSPERREPEAT;
+		result = cycles * (YEARSPERREPEAT * DAYSPERNYEAR + 100 - 4 + 1);
+		tmy += cycles * YEARSPERREPEAT;
+	}
 	for ( ; tmy < newp->tm_year; ++tmy)
 		result += DAYSPERNYEAR + isleap_sum(tmy, TM_YEAR_BASE);
 	result += newp->tm_yday - oldp->tm_yday;
-- 
2.27.0



More information about the tz mailing list