[tz] [PATCH] Restore simpler delta_nonneg code.
Paul Eggert
eggert at cs.ucla.edu
Wed Mar 24 04:21:47 UTC 2021
* zdump.c (delta_nonneg): Undo previous change to this
area that inadvertently installed an unnecessary ‘if’.
---
zdump.c | 14 ++++----------
1 file changed, 4 insertions(+), 10 deletions(-)
diff --git a/zdump.c b/zdump.c
index e1db329..918d09c 100644
--- a/zdump.c
+++ b/zdump.c
@@ -716,16 +716,10 @@ hunt(timezone_t tz, char *name, time_t lot, struct tm *lotmp, time_t hit,
static intmax_t
delta_nonneg(struct tm *newp, struct tm *oldp)
{
- 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;
- }
+ 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;
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