]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
cal: check biggest week number correctly when highlighting
authorSami Kerola <kerolasa@iki.fi>
Thu, 27 Aug 2015 13:21:29 +0000 (14:21 +0100)
committerKarel Zak <kzak@redhat.com>
Mon, 31 Aug 2015 08:15:12 +0000 (10:15 +0200)
This allows Sunday based week 54 be highlighted, and deny week 54 for
Monday based weeks when year has only 52 weeks.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
misc-utils/cal.c
tests/expected/cal/weekarg
tests/ts/cal/weekarg

index dd26532b6778bfc4239932e484cb9641ec9b0ae2..6faac5ca29e2814a3f43f53078801bff3a1f3d28 100644 (file)
@@ -484,7 +484,7 @@ int main(int argc, char **argv)
                                        ctl.req.year, ctl.req.week);
                while (m <= DECEMBER && yday > days_in_month[leap][m])
                        yday -= days_in_month[leap][m++];
-               if (m > DECEMBER) {
+               if (DECEMBER < m && ctl.weektype & WEEK_NUM_ISO) {
                        /* In some years (e.g. 2010 in ISO mode) it's possible
                         * to have a remnant of week 53 starting the year yet
                         * the year in question ends during 52, in this case
index 75e2efbc52da6fe0379238d2b3da9ad77a228d53..610ad9b16c5d346e4da36fda5869a7f6972c418a 100644 (file)
@@ -125,3 +125,23 @@ Julian - Monday-based, week 40 with colors, 3 month
 38 259 260 261 262 263 264 265  43 294 295 296 297 298 299 300  47 322 323 324 325 326 327 328 
 39 266 267 268 269 270 271 272  44 301 302 303 304              48 329 330 331 332 333 334     
 \e[7m40\e[27m 273                                                                                         
+Gregorian - Sunday-based, week 54 with colors, 3 month 
+     November 2000            December 2000             January 2001     
+   Su Mo Tu We Th Fr Sa     Su Mo Tu We Th Fr Sa     Su Mo Tu We Th Fr Sa
+45           1  2  3  4  49                 1  2   1     1  2  3  4  5  6 
+46  5  6  7  8  9 10 11  50  3  4  5  6  7  8  9   2  7  8  9 10 11 12 13 
+47 12 13 14 15 16 17 18  51 10 11 12 13 14 15 16   3 14 15 16 17 18 19 20 
+48 19 20 21 22 23 24 25  52 17 18 19 20 21 22 23   4 21 22 23 24 25 26 27 
+49 26 27 28 29 30        53 24 25 26 27 28 29 30   5 28 29 30 31          
+                         \e[7m54\e[27m \e[7m31\e[27m                                            
+Gregorian - Monday-based, week 53 with colors, 3 month 
+cal: illegal week value: year 2000 doesn't have week 53
+Gregorian - Monday-based, week 52 with colors, 3 month 
+     November 2000            December 2000             January 2001     
+   Mo Tu We Th Fr Sa Su     Mo Tu We Th Fr Sa Su     Mo Tu We Th Fr Sa Su
+44        1  2  3  4  5  48              1  2  3   1  1  2  3  4  5  6  7 
+45  6  7  8  9 10 11 12  49  4  5  6  7  8  9 10   2  8  9 10 11 12 13 14 
+46 13 14 15 16 17 18 19  50 11 12 13 14 15 16 17   3 15 16 17 18 19 20 21 
+47 20 21 22 23 24 25 26  51 18 19 20 21 22 23 24   4 22 23 24 25 26 27 28 
+48 27 28 29 30           \e[7m52\e[27m 25 26 27 28 29 30 \e[7m31\e[27m   5 29 30 31             
+                                                                          
index 55dc327e2f91a0b7657f66239b14fc30e85e565c..19f58c10019af044173e6911e9f50177f4e77232 100755 (executable)
@@ -129,5 +129,31 @@ if [ "$USETERM" == "yes" ]; then
 fi
 $TS_CMD_CAL -3mj $WEEK $MYTIME >> $TS_OUTPUT
 
+MYTIME="31 12 2000"
+PWEEK="week 54 with colors"
+WEEK="--week=54 --color=always"
+ts_log "Gregorian - Sunday-based, $PWEEK, 3 month $x"
+if [ "$USETERM" == "yes" ]; then
+       $TS_CMD_CAL --three --sunday $WEEK $MYTIME
+fi
+$TS_CMD_CAL --three --sunday $WEEK $MYTIME >> $TS_OUTPUT
+
+PWEEK="week 53 with colors"
+WEEK="--week=53 --color=always"
+ts_log "Gregorian - Monday-based, $PWEEK, 3 month $x"
+if [ "$USETERM" == "yes" ]; then
+       $TS_CMD_CAL --three --monday $WEEK $MYTIME
+fi
+$TS_CMD_CAL --three --monday $WEEK $MYTIME >> $TS_OUTPUT 2>&1
+
+PWEEK="week 52 with colors"
+WEEK="--week=52 --color=always"
+ts_log "Gregorian - Monday-based, $PWEEK, 3 month $x"
+if [ "$USETERM" == "yes" ]; then
+       $TS_CMD_CAL --three --monday $WEEK $MYTIME
+fi
+$TS_CMD_CAL --three --monday $WEEK $MYTIME >> $TS_OUTPUT 2>&1
+
+
 ts_finalize