Why Ruby's Date Class Has Constants Named ITALY, ENGLAND, and JULIAN
Ruby’s Date class exposes oddly-named constants like Date::ITALY (2299161), Date::ENGLAND, Date::GREGORIAN, and Date::JULIAN. They turn out to be Julian Day numbers marking when different regions switched from the Julian to the Gregorian calendar. Italy made the jump in October 1582 per Pope Gregory XIII’s bull, skipping ten days entirely — Ruby honors this by raising an error for dates in the gap and jumping straight from October 4 to October 15 when iterating. England held out until 1752, which is why a separate constant exists.
Julian Day numbers themselves are a continuous day count from a synchronized epoch in 4713 BC, designed by Joseph Scaliger as a universal intermediary for converting between calendar systems with differing adoption dates. Date::GREGORIAN and Date::JULIAN are set to negative and positive infinity respectively, meaning ‘the switchover happened infinitely long ago’ or ‘never happens.’ Ruby’s Date initializer accepts a start argument so historical dates can be modeled accurately — for example, Isaac Newton’s birthday is December 25, 1642 in ‘old style’ English reckoning but January 4, 1643 in ‘new style’ Gregorian.
The piece is a tour of how a small piece of standard-library trivia encodes centuries of calendrical politics. Conceptually a Ruby Date is a (Julian day, Gregorian switchover) tuple, and arbitrary switchover values let you model regional adoptions like Russia’s 1918 transition.
Read the full article
Continue reading at Hacker News →This is an AI-generated summary. Read the original for the full story.