util-linux.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] cal: fix julian calendars for large years
@ 2018-01-18  2:21 J William Piggott
  2018-01-22 10:33 ` Karel Zak
  0 siblings, 1 reply; 2+ messages in thread
From: J William Piggott @ 2018-01-18  2:21 UTC (permalink / raw)
  To: Karel Zak; +Cc: util-linux


Before:
cal --r julian 31 12 2147483646
 December 2147483646
Su Mo Tu We Th Fr Sa
 1  2  3  4  5  6  7
 8  9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 31

Patched:
cal --r julian 31 12 2147483646
 December 2147483646
Su Mo Tu We Th Fr Sa
                   1
 2  3  4  5  6  7  8
 9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31

Signed-off-by: J William Piggott <elseifthen@gmx.com>
---
 misc-utils/cal.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/misc-utils/cal.c b/misc-utils/cal.c
index 543fbc6e1..a854eaf9d 100644
--- a/misc-utils/cal.c
+++ b/misc-utils/cal.c
@@ -924,14 +924,15 @@ static int day_in_week(const struct cal_control *ctl, int day,
 	    || (year == ctl->reform_year && REFORMATION_MONTH < month)
 	    || (year == ctl->reform_year
 		&& month == REFORMATION_MONTH && 13 < day)) {
-		int64_t long_year = year;
-		return (long_year + (year / 4) - (year / 100) + (year / 400) +
-			reform[month - 1] + day) % DAYS_IN_WEEK;
+		return ((int64_t) year + (year / 4)
+			- (year / 100) + (year / 400)
+			+ reform[month - 1] + day) % DAYS_IN_WEEK;
 	}
 	if (year < ctl->reform_year
 	    || (year == ctl->reform_year && month < REFORMATION_MONTH)
 	    || (year == ctl->reform_year && month == REFORMATION_MONTH && day < 3))
-		return (year + year / 4 + old[month - 1] + day) % DAYS_IN_WEEK;
+		return ((int64_t) year + year / 4 + old[month - 1] + day)
+			% DAYS_IN_WEEK;
 	return NONEDAY;
 }
 

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] cal: fix julian calendars for large years
  2018-01-18  2:21 [PATCH] cal: fix julian calendars for large years J William Piggott
@ 2018-01-22 10:33 ` Karel Zak
  0 siblings, 0 replies; 2+ messages in thread
From: Karel Zak @ 2018-01-22 10:33 UTC (permalink / raw)
  To: J William Piggott; +Cc: util-linux

On Wed, Jan 17, 2018 at 09:21:02PM -0500, J William Piggott wrote:
>  misc-utils/cal.c | 9 +++++----
>  1 file changed, 5 insertions(+), 4 deletions(-)

Applied, thanks.

-- 
 Karel Zak  <kzak@redhat.com>
 http://karelzak.blogspot.com

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2018-01-22 10:34 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-01-18  2:21 [PATCH] cal: fix julian calendars for large years J William Piggott
2018-01-22 10:33 ` Karel Zak

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).