Calendar block with ISO weeknumbers

Calendar block with ISO weeknumbers

by Ger Tielemans -
Number of replies: 1

When your teachers and students use weeknumbers in their communication and follow the ISO-8601 standard for weeknumbers, you can add these numbers to your mini calendar block. Make these three changes in the calendar library and you will see the changes everywhere where the mini calendar is used. (works for 1.9.x, 2.4.x, 2.5.x, 2.6.x...)

First important step: change the settings for the week days in Moodle: make Monday the first day of the week. (according the iso-8601 standard) ...would be nice to see on the settings page in the core distribution - when you make this change to Monday -  a checkbox popup with the text: do you wish to see iso-8601 numbers in your mini calendars?

Then make these 3 changes in \calendar\lib.php 

1.

 //$content .= '<tr class="weekdays">'; // Header row: day names
  $content .= '<tr class="weekdays"><td bgcolor=#E5EDE4;>nr</td>'; // Header row: day names

2.

// $content .= '</tr><tr>'; // End of day names; prepare for day numbers
     $weeknr = strftime('%U',time());
     $weeknr=strftime('%U',mktime (6,6,6,$m,7,$y));
     $weeknr=$weeknr +1; $weeknr=$weeknr-1; // formatting trick
$content .= '</tr><tr><td bgcolor=#E5EDE4;>'.$weeknr.'</td>'; // End of day names; prepare for day numbers

3.

// We need to change week (table row)
// $content .= '</tr><tr>';
  $weeknr=$weeknr+1;
        if ($weeknr == 53) {$weeknr= "(53)";}
        $content .= '</tr><tr><td bgcolor=#E5EDE4;>'.$weeknr.'</td>';

If you combine twelve of these minicalendars on one page, you end up with this smile

 

Attachment ScreenShot093.png
Average of ratings: -
In reply to Ger Tielemans

OOPS: correction for Calendar block with ISO weeknumbers

by Ger Tielemans -

Works now from 2015 until 2023 (checked in 2.6 and 2.9)

1.

//$content .= '<tr class="weekdays">'; // Header row: day names
$content .= '<tr class="weekdays"><td bgcolor=#E5EDE4;>nr</td>'; // Header row: day names

2.

// $content .= '</tr><tr>'; // End of day names; prepare for day numbers
$weeknr = date("W", strtotime('-1 day', $display->tstart) );
$weeknrB=$weeknr;
if ($weeknr == 52) {$weeknrB = "52";   $weeknr = 0;}
if ($weeknr == 53) {$weeknrB = "(53)"; $weeknr = 0 ;}
if (($startwday == 1) ) {$weeknr = $weeknr +1;$weeknrB=$weeknrB + 1;}
if ( $weeknrB > 52 ) {$weeknrB = "1"; $weeknr = 1 ;}
$content .= '</tr><tr><td bgcolor=#E5EDE4;>'.$weeknrB.'</td>'; // End of day names; prepare for day numbers

3.

// We need to change week (table row)
// $content .= '</tr><tr>';
$weeknr=$weeknr+1;
$weeknrB=$weeknr;
if ($weeknr == 53) {$weeknrB= "(53)"; $weeknr = 0;}
$content .= '</tr><tr><td bgcolor=#E5EDE4;>'.$weeknrB.'</td>';