[paid accounts] Sidebar calendar week starts on Monday instead of Sunday

Jun 04, 2005 00:13

To make the sidebar calendar start the week on Monday instead of Sunday

1. Create a new theme layer. (Follow the steps in this post to create a theme layer.) If you have already created a theme layer for the style, just add the following code to it.

2. Copy the following code and paste it after the layerinfo statements.



# ---------------------------------------------------------------------------
# Sidebar calendar's week starts from Monday instead of Sunday
# ---------------------------------------------------------------------------

function print_sidebar_calendar()
{
var string calendar;
var Page p = get_page();
var YearMonth m = $p->get_latest_month();
var string month = $m->month_format();
if($m.has_entries) {
$calendar = """
  • """;
    var YearWeek[] theWeeks = $m.weeks;

    var YearMonth NewMonth;
    var int NewWeek = 0;
    var int NewDay;
    var int NewStartDay;

    var int count = 0;
    foreach var YearWeek w ($m.weeks)
    {
    if ($w.pre_empty == 0)
    {
    $NewStartDay = 6;
    }
    else
    {
    $NewStartDay = $w.pre_empty - 1;
    }
    foreach var YearDay d ($w.days)
    {
    if ($d.day > 0)
    {
    $NewMonth.weeks[$NewWeek].days[$count] = $d;
    }
    $NewStartDay++;
    $count++;
    if ($NewStartDay >= 7)
    {
    if ($NewWeek == 0)
    {
    $NewMonth.weeks[$NewWeek].pre_empty = 7 - $count;
    }
    else
    {
    $NewMonth.weeks[$NewWeek].post_empty = 7 - $count;
    }
    $NewStartDay = 0;
    $count = 0;
    $NewWeek++;
    }
    }
    }
    if ($count >0)
    {
    $NewMonth.weeks[$NewWeek].post_empty = 7 - $count;
    }

    foreach var YearWeek w ($NewMonth.weeks) {
    $calendar = $calendar + "";
    var YearDay[] theDays = $w.days;
    var int pre = $w.pre_empty;
    if($pre > 0) {
    $calendar = $calendar + """ """;
    }
    foreach var YearDay d ($theDays) {
    if ($d.num_entries) {
    $calendar = $calendar + """ $d.day""";
    } else {
    $calendar = $calendar + """$d.day""";
    }
    }
    $calendar = $calendar + "\n";
    }

    $calendar = $calendar + "
  • ";
    }
    $month = """
  • $month
  • """;
    if ($calendar != "") {
    print_sidebar_box($month, $calendar);
    }
    }

    This only make the sidebar calendar start the week on Monday. It doesn't change the start-of-week day in the archive page.
    (Which is rather curious, because we have the reg_firstdayofweek property built into the core, but it doesn't seem to do anything.)

    !tutorial, sidebar, paid accounts

    Previous post Next post
    Up