* [PATCH 1/2] cal: fix week calculations for 1752
@ 2018-01-22 12:01 J William Piggott
2018-01-22 12:03 ` [PATCH 2/2] cal: fix first week calculation J William Piggott
2018-01-22 13:28 ` [PATCH 1/2] cal: fix week calculations for 1752 Karel Zak
0 siblings, 2 replies; 4+ messages in thread
From: J William Piggott @ 2018-01-22 12:01 UTC (permalink / raw)
To: Karel Zak; +Cc: util-linux
Before:
cal --week=39 1752
September 1752
Su Mo Tu We Th Fr Sa
36 1 2 14 15 16
37 17 18 19 20 21 22 23
38 24 25 26 27 28 29 30
Patched:
cal --week=39 1752
October 1752
Su Mo Tu We Th Fr Sa
39 1 2 3 4 5 6 7
40 8 9 10 11 12 13 14
41 15 16 17 18 19 20 21
42 22 23 24 25 26 27 28
43 29 30 31
Signed-off-by: J William Piggott <elseifthen@gmx.com>
---
misc-utils/cal.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/misc-utils/cal.c b/misc-utils/cal.c
index a854eaf9d..1b03857f6 100644
--- a/misc-utils/cal.c
+++ b/misc-utils/cal.c
@@ -997,6 +997,9 @@ static int week_to_day(const struct cal_control *ctl)
wday = day_in_week(ctl, 1, JANUARY, ctl->req.year);
yday = ctl->req.week * DAYS_IN_WEEK - wday;
+ if (ctl->req.year == ctl->reform_year && yday >= YDAY_AFTER_MISSING)
+ yday += NUMBER_MISSING_DAYS;
+
if (ctl->weektype & WEEK_NUM_ISO)
yday -= (wday >= FRIDAY ? -2 : 5);
else
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH 2/2] cal: fix first week calculation
2018-01-22 12:01 [PATCH 1/2] cal: fix week calculations for 1752 J William Piggott
@ 2018-01-22 12:03 ` J William Piggott
2018-01-22 13:28 ` [PATCH 1/2] cal: fix week calculations for 1752 Karel Zak
1 sibling, 0 replies; 4+ messages in thread
From: J William Piggott @ 2018-01-22 12:03 UTC (permalink / raw)
To: Karel Zak; +Cc: util-linux
Commit efafeaf set 1 Jan as week 1, but the change
was missed in week_to_day() and in the man page.
Before
cal --week=40 --iso 1752
October 1752
Su Mo Tu We Th Fr Sa
41 1 2 3 4 5 6 7
42 8 9 10 11 12 13 14
43 15 16 17 18 19 20 21
44 22 23 24 25 26 27 28
45 29 30 31
Patched
cal --week=40 --iso 1752
September 1752
Su Mo Tu We Th Fr Sa
36 1 2
37 3 4 5 6 7 8 9
38 10 11 12 13 14 15 16
39 17 18 19 20 21 22 23
40 24 25 26 27 28 29 30
Signed-off-by: J William Piggott <elseifthen@gmx.com>
---
misc-utils/cal.1 | 12 ++++++------
misc-utils/cal.c | 2 +-
2 files changed, 7 insertions(+), 7 deletions(-)
diff --git a/misc-utils/cal.1 b/misc-utils/cal.1
index f99c6b495..60eaa5c3b 100644
--- a/misc-utils/cal.1
+++ b/misc-utils/cal.1
@@ -195,13 +195,13 @@ highlighted if the calendar is displayed on a terminal. If no parameters are
specified, the current month's calendar is displayed.
.SH NOTES
A year starts on January 1. The first day of the week is determined by the
-locale.
+locale or the
+.BR \-\-sunday \ and \ \-\-monday \ options.
.PP
-The week numbering depends on the choice of the first day of the week. If Sunday
-(the default) is used for the first day of the week, then the customary North
-American numbering will be used, i.e. the first Sunday of the year starts the
-first week. If Monday is selected, then the ISO-8601 standard week numbering
-is used, where the first Thursday of the year is in week number 1.
+The week numbering depends on the choice of the first day of the week. If it
+is Sunday then the customary North American numbering is used, where 1 January
+is in week number 1. If it is Monday then the ISO 8601 standard week numbering
+is used, where the first Thursday is in week number 1.
.SH COLORS
Implicit coloring can be disabled as follows:
.RS
diff --git a/misc-utils/cal.c b/misc-utils/cal.c
index 1b03857f6..5a6364a27 100644
--- a/misc-utils/cal.c
+++ b/misc-utils/cal.c
@@ -1003,7 +1003,7 @@ static int week_to_day(const struct cal_control *ctl)
if (ctl->weektype & WEEK_NUM_ISO)
yday -= (wday >= FRIDAY ? -2 : 5);
else
- yday -= (wday == SUNDAY ? 6 : -1); /* WEEK_NUM_US */
+ yday -= 6; /* WEEK_NUM_US */
if (yday <= 0)
return 1;
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH 1/2] cal: fix week calculations for 1752
2018-01-22 12:01 [PATCH 1/2] cal: fix week calculations for 1752 J William Piggott
2018-01-22 12:03 ` [PATCH 2/2] cal: fix first week calculation J William Piggott
@ 2018-01-22 13:28 ` Karel Zak
2018-01-22 20:58 ` J William Piggott
1 sibling, 1 reply; 4+ messages in thread
From: Karel Zak @ 2018-01-22 13:28 UTC (permalink / raw)
To: J William Piggott; +Cc: util-linux
On Mon, Jan 22, 2018 at 07:01:23AM -0500, J William Piggott wrote:
> misc-utils/cal.c | 3 +++
> 1 file changed, 3 insertions(+)
The both patches applied, and "--week=40 1752" added to tests.
Karel
--
Karel Zak <kzak@redhat.com>
http://karelzak.blogspot.com
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH 1/2] cal: fix week calculations for 1752
2018-01-22 13:28 ` [PATCH 1/2] cal: fix week calculations for 1752 Karel Zak
@ 2018-01-22 20:58 ` J William Piggott
0 siblings, 0 replies; 4+ messages in thread
From: J William Piggott @ 2018-01-22 20:58 UTC (permalink / raw)
To: Karel Zak; +Cc: util-linux
On 01/22/2018 08:28 AM, Karel Zak wrote:
> On Mon, Jan 22, 2018 at 07:01:23AM -0500, J William Piggott wrote:
>> misc-utils/cal.c | 3 +++
>> 1 file changed, 3 insertions(+)
>
> The both patches applied, and "--week=40 1752" added to tests.
I didn't look at the test, but note that the week 40 bug only affected
the proleptic Gregorian output:
cal --week=40 --iso 1752
The week 39 bug only affected the default (1752) output:
cal --week=39 1752
You might want to hold off on updating the tests until my queue of bug
fixes is emptied ;)
>
> Karel
>
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2018-01-22 20:58 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-01-22 12:01 [PATCH 1/2] cal: fix week calculations for 1752 J William Piggott
2018-01-22 12:03 ` [PATCH 2/2] cal: fix first week calculation J William Piggott
2018-01-22 13:28 ` [PATCH 1/2] cal: fix week calculations for 1752 Karel Zak
2018-01-22 20:58 ` J William Piggott
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.