Feed on Posts or Comments 05 February 2012

MediaWiki robchurch on 02 Jan 2007 12:29 pm

Escape from dates!

Well, as is typical with these sorts of things, I didn’t get a lot done on the shiny new date reformatting class following the last post; damn festive season, gets in the way of everything. Still, I managed to make some significant progress yesterday evening, and this morning.

I realised that a major problem occurring was that full dates were being happily refactored, but corrupted when partial dates were processed.

For example, “20 January 2006″ would be happily refactored to “January 20, 2006″, for instance. Unfortunately, when it came time to match against stuff like “month, day” (no year), this would pick up the first part and…cause a horrible mess.

I’ve combated this using a simple but hopefully fast and adequate placeholder system – once a date is successfully refactored, it is stashed in memory, and a placeholder string is assigned to it. This string is composed of the concatenated values “DATEPARSER_”, a hash of the original chunk of text itself, and then “_X”, where X is just a numerical index identifying the result text. This is rapidly switched back in place when all the actual date refactoring has been accomplished.

After dealing with a misplaced $this which was causing the new FormattableDate class to not actually load any information, everything started working! I’ve implemented a few more “letters” – that is, identifiers for a particular part of a date (see http://www.php.net/manual/en/function.date.php), and all the destination formats are now possible.

What next? All I have to do is write a couple more regular expressions to pick up the last remaining possible formats, and then I can move onto testing. And for that, I plan to use Avar’s shiny new testing framework…

One Response to “Escape from dates!”

  1. on 04 Jan 2007 at 10:27 am 1.Stephen Turner said …

    Rob,

    Thank you so much for working on this. I’m really pleased to see that this is receiving some attention. It’s been one of my pet hates for a long time.

Trackback This Post | Subscribe to the comments through RSS Feed

Leave a Reply