[tz] [PATCH 2/5] Minor time2sub refactor

Paul Eggert eggert at cs.ucla.edu
Sun Nov 20 05:13:09 UTC 2022


* localtime.c (time2sub): Refactor to do subtraction
at compile-time rather than addition at runtime.
Use yourtm.tm_year instead of y; they’re equal, and
using yourtm.tm_year simplifies later patches.
---
 localtime.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/localtime.c b/localtime.c
index 9fa1bf7..f9655ed 100644
--- a/localtime.c
+++ b/localtime.c
@@ -2039,7 +2039,7 @@ time2sub(struct tm *const tmp,
 	yourtm.tm_year = y;
 	if (yourtm.tm_sec >= 0 && yourtm.tm_sec < SECSPERMIN)
 		saved_seconds = 0;
-	else if (y + TM_YEAR_BASE < EPOCH_YEAR) {
+	else if (yourtm.tm_year < EPOCH_YEAR - TM_YEAR_BASE) {
 		/*
 		** We can't set tm_sec to 0, because that might push the
 		** time below the minimum representable time.
-- 
2.38.1



More information about the tz mailing list