From b4291761c2ebeea3f4738ffbec51cb37b49377c6 Mon Sep 17 00:00:00 2001 From: June McEnroe Date: Wed, 5 Oct 2022 23:36:30 -0400 Subject: Fix same month, different day diffs This fixes it expressing a 355d difference, for example, as 1y -1m 20d. Just switching to <= would make it express 365d as 12m rather than 1y. --- bin/when.y | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'bin') diff --git a/bin/when.y b/bin/when.y index c94c5514..46651ebb 100644 --- a/bin/when.y +++ b/bin/when.y @@ -121,7 +121,10 @@ static struct tm dateDiff(struct tm a, struct tm b) { .tm_mon = a.tm_mon - b.tm_mon, .tm_mday = a.tm_mday - b.tm_mday, }; - if (a.tm_mon < b.tm_mon) { + if ( + a.tm_mon < b.tm_mon || + (a.tm_mon == b.tm_mon && a.tm_mday < b.tm_mday) + ) { diff.tm_year--; diff.tm_mon += 12; } -- cgit 1.4.1