Riding The Breeze

Jump to content

Additional information

Categories


Monday first in MovableType calendar

Feb 2009
01

When you display a calendar in Movabletype using tags from Calendar's set you get a calendar with Sunday as first day of the week.

In many countries (like Italy) weeks start on Monday, so, I needed to change this beahvior. I thought I could change something in the "Settings" panel or in the Config file to achive this but I was wrong !

After a short searching I realized that I wasn't the only one with this problem, and I've also found this solution that works by shifting by one the day returned by wday_from_ts.

At the beginning everything seemed to works fine but I immediately realized that this hack effected also the result of tags connected to a date like <$mt:EntryDate$>. Basically instead of getting Sunday February 1th 2009 I was getting Saturday February 1th 2009, as you can imagine, this is quite a big problem, especially for a blog where date matters.

I started to look for another way to solve the problem and I realized that the only possibility was modify the function that handle the calendar tags.

The Solution

Open /lib/MT/Template/ContextHandlers.pm and modify these 2 lines from

my $pad_start = wday_from_ts($y, $m, 1);
my $pad_end = 6 - wday_from_ts($y, $m, $days_in_month);

to

my $pad_start_tmp = wday_from_ts($y, $m, 1);
my $pad_start = ($pad_start_tmp == 0) ? 6 : $pad_start_tmp - 1;
my $pad_end = wday_from_ts($y, $m, $days_in_month) + 1;


Your Comment

You can use these tags:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>




Credits

Template designed by praegnanz.de.