Publishing with old dates in Movable Type

Jon Udell recently posted about trying to get a WordPress.com blog working well with content that has historical dates. This reminded me that I’ve been meaning to write up how I got Movable Type working well with the 17th century dates of The Diary of Samuel Pepys.

The problem

For a project like this we have blog entries related to specific dates in the past, which are published on certain dates in the present. Each entry therefore has two dates associated with it: the original date on which it was written (eg, 30 July 1667) and the date on which it’s published by Movable Type (30 July 2010).

Because MT understandably only lets you give a single date to an entry, there are two ways of reconciling these, neither of which are perfect.

The first option is to use the current, modern date for each entry. This means that the correct date will appear in RSS/Atom feeds (feed readers may get confused if you publish entries with very old dates), and Scheduled publishing will work as intended. The downside is that if you use Archive URLs that contain date elements (eg, “/archive/2010/07/30/blog-post.php”) then those will use the published date (like on the Orwell Diaries site) rather than the old date. You might be OK with this, but I prefer using the original date.

The second option is to use the historical date for each entry. MT doesn’t complain if you tell it an entry is from “1667-07-30”, and this means you’ll get the “correct” date elements in any URLs. But you’ll also get this old date in your RSS/Atom feeds and Scheduled publishing won’t work: any scheduled posts will be published straight away as MT thinks they’re way, way overdue.

Wanting to have the “correct” URLs, I went for the second option, which requires a few bits of customisation, outlined below.

(I suspect there may now be a third, possibly better, way of doing some of this, using a “Date and Time” Custom Field on the Entry, but I settled on my solution before Custom Fields existed.)

Fixing the RSS/Atom feeds

We want to make sure the publish date of blog entries in the feeds are the correct, contemporary date, rather than the historical date. eg, ‘2010-07-30’ rather than ‘1667-07-30’.

I solved this by using Brad Choate’s Regex plugin. At the start of my Feed template I have this ugly mess:

<MTRegexDefine>s|1660|2003|</MTRegexDefine>
<MTRegexDefine>s|1661|2004|</MTRegexDefine>
<MTRegexDefine>s|1662|2005|</MTRegexDefine>
<MTRegexDefine>s|1663|2006|</MTRegexDefine>
<MTRegexDefine>s|1664|2007|</MTRegexDefine>
<MTRegexDefine>s|1665|2008|</MTRegexDefine>
<MTRegexDefine>s|1666|2009|</MTRegexDefine>
<MTRegexDefine>s|1667|2010|</MTRegexDefine>
<MTRegexDefine>s|1668|2011|</MTRegexDefine>
<MTRegexDefine>s|1669|2012|</MTRegexDefine>

This prepares the ability to translate historical years to years in the present.

Then, in parts of the Feed template that require the current, modern date, I do something like this:

<dc:date><$mt:EntryDate format="%Y" regex="1"$><$mt:EntryDate format="-%m-%dT%H:%M:%S" language="en"$><$mt:BlogTimezone$></dc:date>

I’ve put the year part of the date (“%Y”) into its own tag and added regex=”1”, which is telling MT to perform the search and replace specified above on the year. This translates 1660 into 2003, 1661 to 2004, etc.

Having said that, it might be possible to achieve the same thing using MT’s newer built-in modifiers these days, such as regex_replace.

Fixing Scheduled posting

Because each entry’s publish date is set so far in the past, MT’s script that checks for scheduled posts will think the entry is extremely overdue and will post it immediately.

To fix this I had to modify Movable Type’s code slightly — this is a bit nasty, and you have to remember to manually apply the change to the new file whenever you update to a new version.

Go to where you keep your Movable Type CGI files, and open the file lib/MT/WeblogPublisher.pm and find this line:

push @queue, $entry->id if $entry->authored_on le $now;

At the time of writing, it’s somewhere near line 1800. Replace that line with this:

#### Start old date hack.
if ($blog->id == 3 || $blog->id == 6) {
    my $oldnow = $now - 3430000000000;
    push @queue, $entry->id if $entry->authored_on le $oldnow;
} else {
    ### This is the original line.
    push @queue, $entry->id if $entry->authored_on le $now;
}
#### End old date hack.

You’ll need to make a couple of modifications though. I use this fix for two Pepys-related blogs, with blog_ids of 3 and 6. You’ll need to change that line to use whatever blog_ids are relevant to you. If you’re only using this on one blog, the first couple of lines above will look something like this

#### Start old date hack.
if ($blog->id == 3) {

if your blog_id is 3. Adding this makes sure we don’t mess around with the scheduled publishing for any of the other blogs in the system.

The second modification is to that long number: “3430000000000”. This is the amount of time between your historical date and the date on which you want the entries published. In Pepys’ case, the diaries are 343 years behind today. So this is the number of years plus ten zeroes. If your dates aren’t whole years apart you could probably add months and days, which use the next four zeroes between them. eg, “791107000000” would be for dates that are 79 years, 11 months and 7 days apart.

With that done, MT’s Scheduled posting code will add that amount of time to your relevant blog entries before deciding whether it’s time to be published or not.

Conclusion

I think that’s all the customisation I did for this issue. As I say, there may be easier ways these days, but it’s taken me seven-and-a-half years to get round to writing this up.

Commenting is disabled on posts once they’re 30 days old.

9 Jul 2010 at Twitter

  • 7:26pm: Talking people on the train are even more distracting and annoying when you realise they're almost exactly the same as you.
  • 4:13pm: @synx508 Awww, but it's quite sweet to get a chunk of 20th century delivered every year.
  • 2:53pm: Replaced one old, still wrapped Yellow Pages with a newer, smaller, wrapped Yellow Pages. They are simply memories of how we used to live.
  • 1:33pm: Breakfast, Pepys, new office fans, Chart Hits 83, bloggage, ticking things off. Time for the weekend.
  • 9:25am: We've got the washing up situation sorted, but someone MIS-SHELVED A BOOK! Chaos, anarchy and revolution rule in #BRIG.
  • 9:06am: @dorianmoore But when (if) the code finally works, all is good. Phew.

9 Jul 2010 in Links

Music listened to most that week

  1. Ikonika (22)
  2. Throwing Muses (13)
  3. The Wolfgang Press (12)
  4. Dinosaur Jr. (10)
  5. Miles Davis (8)
  6. Luscious Jackson (7)
  7. Yazoo (2)
  8. Nick Drake (2)
  9. Prince (1)
  10. Los Campesinos! (1)

More at Last.fm...