Posts Tagged with Easter

When’s Easter?

I’ve been doing a lot with Javascript and PHP lately thanks to a personal project. I’ve finally wrapped my head around object-oriented programming (sort of) in PHP, as well as figured out how to use jQuery for some nifty dynamic stuff. One of the requirements of this project is a dynamic site theming engine… thing… that allows the user a good deal of customization with three basic options: Default, Automatic, and Custom. Default sticks to the default site theme, while Custom allows a user to tweak the available options independently.

Automatic, however, themes the site based on the current season (Autumn, Winter, Spring, or Summer) as well as using special themes for holidays (Christmas, New Year’s, etc.). Most holidays fall on the same date every year, so this is really easy to do. Some are a little trickier, though. Thanksgiving, for example, is the fourth thursday of November, a target that can shift from year to year.

A little searching came up with a simple PHP function that’ll determine when Thanksgiving actually is during any given year using the strtotime() function. We can give it something like “thursday, novemeber 2008 + 3 weeks” and it’ll spit out the appropriate timestamp for Thanksgiving in 2008. Easy.

Easter is a little trickier, though; there’s no simple way to get the “first Sunday after the first full moon on or after March 21.” Just reading that makes it sound like it would take some kind of archaic, trance-inducing mysticism to figure out (assuming you don’t have a calendar handy). What’s one to do? Why, use the easter_date() function of course!

easter_date — Get Unix timestamp for midnight on Easter of a given year

Just give it a year and this bad boy spits out Easter like there’s no tomorrow. Or something. It’s not perfect but it gets the job done well enough, and I nearly died of laughter when I saw it. I just love the fact that there’s a dedicatd PHP function for computing what day Easter falls on in a given year.