English Ordinal Suffix
As I was previewing the post published yesterday, I realized that the post's date was marked as January 31th, 2009. Looking through my templates, I saw that I had been lazy and hard-coded "th" into the template. Investigating further, I discovered that strftime (the method that Liquid Templates use to format dates) had no way to output the correct suffix.
There didn't seem to be any clean place to put it in the layout or in LimeSpot, but LimeSpot happens to let you add arbitrary javascript to your pages so I added this little snippet:
<!-- hack -->
<script type="text/javascript">
$$('.post_date').each(function(date) {
var day = date.select('.day')[0];
var modDay = day.innerHTML % 10;
var suffix = 'th'; // default case
if(modDay == 1) { suffix = 'st'; }
if(modDay == 2) { suffix = 'nd'; }
if(modDay == 3) { suffix = 'rd'; }
date.select('.th')[0].update(suffix);
});
</script>
Comments