Simon Griffee
Design consulting, art direction, photography.

Textpattern, Strftime Save Daylight Saving Time

Published 2005 April 8

I never liked Daylight Saving Time. Losing an hour of sleep before joining the Roman rally-race to work six months of the year made me particularly unhappy.

Freelancing from home means rush-hour traffic is behind me, but Daylight Saving Time (DST) has struck again. This time the gloom was caused by recent birthday-related posts I made to this website, which is powered by Textpattern. The article posted-dates were wrongly displaying as a day previously; for example, an article I had set to be published on April 6th displayed a posted-date of April 5th.

I tracked the problem down to the recent DST change and the absence of a setting for it on the Textpattern site administration panel. Changing the Time Zone setting to GMT+02:00 instead of GMT+01:00 (thus simulating the dreaded DST) worked, but was a hack I wouldn’t want to manually repeat or worry about every six months.

I upgraded to Textpattern RC3 and found that now a setting for DST was available and that it made the posted-dates work properly again. Except now the custom-defined date format on the bottom of each article only showed the PHP date variables instead of an actual day, month and year.

Some Googling brought me to this discussion thread on the helpful Textpattern forum, which gave me the answer. In Textpattern RC3 a new PHP time function called strftime is used to format dates. Strftime formats a local time and date according to locale settings and by using its string format in my txp tags as for example: <txp:posted format="%e %B %Y" /> …my problem was solved. Strftime along with the new Textpattern DST preferences setting saved me yet another Daylight Saving Time woe.