PHP Bank Holidays, mainly Easter!

I need to calculate bank holidays in the UK as part of a project I’m working on. You might think this would be easy, but then you realise that Easter moves, Christmas and Boxing Day bank holidays rollover if they fall on a weekend etc.

The project involves showing some different content based on whether it’s a normal working day or not (evenings, weekends and bank holidays), this lead to a little rabbit warren that I wanted to take you down.

There’s a great function on PHP.net’s calendar reference, by David Scourfield, that looks like it does the job but being the person I am I really wanted to understand it. Most of it made common sense, New Years Day, May Day, August Bank Holiday are all pretty static.

Christmas and Whitsun both look at a specific date, see what date that falls on and then calculate appropriate bank holidays and rollover bank holidays as necessary.

Easter Bank Holidays

Easter is fascinating though, I’ve never seen a history lesson on PHP.net, it makes use of the function easter_days();

(PHP 4, PHP 5, PHP 7)
easter_days — Get number of days after March 21 on which Easter falls for a given year

It should be noted that if you know that Easter falls within the valid unix timestamp range (1970 – 2037) then you can use easter_date().

Both function references feature a similar history lesson:

The date of Easter Day was defined by the Council of Nicaea in AD325 as the Sunday after the first full moon which falls on or after the Spring Equinox. The Equinox is assumed to always fall on 21st March, so the calculation reduces to determining the date of the full moon and the date of the following Sunday. The algorithm used here was introduced around the year 532 by Dionysius Exiguus. Under the Julian Calendar (for years before 1753) a simple 19-year cycle is used to track the phases of the Moon. Under the Gregorian Calendar (for years after 1753 – devised by Clavius and Lilius, and introduced by Pope Gregory XIII in October 1582, and into Britain and its then colonies in September 1752) two correction factors are added to make the cycle more accurate.

See you learn something new every day!

Photo by Jinho.Jung

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.