Package list libhdate / faa5fa7
feb.patch: calendars of February mat have more than 4 weeks (Closes: #696814). Tzafrir Cohen 7 years ago
2 changed file(s) with 85 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
1515 and in files.
1616 - nested_extern.patch - Don't #include files inside a function.
1717 - size_t.patch - int vs. size_t issues.
18 * feb.patch: calendars of February mat have more than 4 weeks (Closes:
19 #696814).
1820
1921 -- Tzafrir Cohen <tzafrir@debian.org> Thu, 01 Nov 2012 16:53:34 +0200
2022
0 Description: February may take more than 4 calendar lines
1 Author: Tzafrir Cohen <tzafrir@debian.org>
2 Bug-Debian: http://bugs.debian.org/696814
3
4 Fix the check for the number of separate weeks in each month (calender
5 lines to print). The code considered February to always have four such
6 weeks when in fact it normally spreads to 5.
7
8 The original and simple patch by Yair Yoram did not account for leap
9 years in which February is 29 days (using __isleap()). Doing so requires
10 passing along the year number. While I was at it, I simplified the code
11 in the function.
12
13 --- a/examples/hcal/hcal.c
14 +++ b/examples/hcal/hcal.c
15 @@ -1161,26 +1161,27 @@ int print_calendar ( const int current_m
16 int previous_year, next_year;
17 int jd_current_month, jd_previous_month, jd_next_month;
18
19 - void how_many_calendar_lines( int month, int start_dow )
20 + void how_many_calendar_lines( int month, int start_dow, int year)
21 {
22 + int days_in_month = 31;
23 + int gross_days_of_month; /* incl. slack of previous month */
24 +
25 switch (month)
26 {
27 case 4:
28 case 6:
29 case 9:
30 - case 11: if (start_dow == 7) max_calendar_lines = 6;
31 - else if (max_calendar_lines == 4) max_calendar_lines = 5;
32 - break;
33 - case 1:
34 - case 3:
35 - case 5:
36 - case 7:
37 - case 8:
38 - case 10:
39 - case 12: if (start_dow > 5) max_calendar_lines = 6;
40 - else if (max_calendar_lines == 4) max_calendar_lines = 5;
41 - break;
42 + case 11:
43 + days_in_month = 30; break;
44 + case 2:
45 + if (__isleap(year))
46 + days_in_month = 29;
47 + else
48 + days_in_month = 28;
49 + break;
50 }
51 + gross_days_of_month = days_in_month + (start_dow - 1);
52 + max_calendar_lines = (gross_days_of_month + 6) / 7;
53 }
54
55 /*********************************************************
56 @@ -1190,7 +1191,7 @@ int print_calendar ( const int current_m
57 *********************************************************/
58 hdate_set_gdate (&h, 1, current_month, current_year);
59 jd_current_month = h.hd_jd - h.hd_dw + 1;
60 - how_many_calendar_lines( h.gd_mon, h.hd_dw );
61 + how_many_calendar_lines( h.gd_mon, h.hd_dw, h.gd_year);
62
63 /*********************************************************
64 * three months, side-by-side
65 @@ -1212,7 +1213,7 @@ int print_calendar ( const int current_m
66 }
67 hdate_set_gdate (&h, 1, previous_month, previous_year);
68 jd_previous_month = h.hd_jd - h.hd_dw + 1;
69 - how_many_calendar_lines( h.gd_mon, h.hd_dw );
70 + how_many_calendar_lines( h.gd_mon, h.hd_dw, h.gd_year);
71
72 /*********************************************************
73 * next month
74 @@ -1229,7 +1230,7 @@ int print_calendar ( const int current_m
75 }
76 hdate_set_gdate (&h, 1, next_month, next_year);
77 jd_next_month = h.hd_jd - h.hd_dw + 1;
78 - how_many_calendar_lines( h.gd_mon, h.hd_dw );
79 + how_many_calendar_lines( h.gd_mon, h.hd_dw, h.gd_year);
80 }
81
82