The Summer Solstice and the Programmer

Calculating the Changing Date of Midsummer Day

© Mark Alexander Bain

Jun 19, 2009
A Typical Summer Solstice at Stonehenge, MorgueFile
The Summer Solstice does not occur on the same day every year. How can a programmer cope with this changing date?

As May turns into June and the summer days warm up many Pagans, Neopagans and Druids turn their minds to converging on a number of ancient stone circles around the United Kingdom. Some will be heading for the most famous – Stonehenge.

Others will be heading for lesser known ones – such as Long Meg and her daughters. And all of them preparing to celebrate the Summer Solstice. The question is, of course, when is the Summer Solstice?

The Changing Summer Solstice

It may be a surprise to learn that the Summer Solstice does not occur on the same date every year. If asked, most people will reply that the Summer Solstice occurs on June 21st. And that's true. Most of the time.

However, the Summer Solstice may also occur on June 20th or June 22nd (although the next time that the Summer Solstice is due to occur on June 22nd is 2203, so that won't be an issue for most readers of this article). The actual days for the next few years are:

  • 2009 – 2011: June 21st
  • 2012: June 20th
  • 2013 – 2015: June 21st
  • 2016: June 20th
  • 2017 – 2019: June 21st
  • 2020: June 20th

The reason for these changes is quite simply because the calendar is fixed to 365 days (plus one every leap year) whereas the Earth takes 365.24199 days to circle the Sun.

The next question is, therefore, how can a programmer handle these changes in an application or a web page?

Handling the Changing Summer Solstice in a Program

It is quite possible to write a program that calculates the Summer Solstice date for any year. However, to be honest, services such as USNO (the United States Naval Observatory) have done so much work in this area that there is really no need.

It is a much more efficient use of the programmer's time just to use the data produced by USNO, all of which is readily available from their web site. Rather than calculate everything from scratch, the programmer can quickly create an array that will contain the Summer Solstice dates. For example:

Dim solstice_days (2009 to 2020) As Integer

The programmer can then populate this array with the correct information:

Dim y As Integer
For y = 2009 to 2011
solstice_days (y) = 21
Next y
solstice_days (2012) = 20
For y = 2013 to 2015
solstice_days (y) = 21
Next y
solstice_days (2016) = 20
For y = 2017 to 2016
solstice_days (y) = 21
Next y
solstice_days(2020) = 20

And then the correct date for the the current year can extracted:

Dim current_year As Integer: current_year = Year(Now)
msgbox current_year & ": " & solstice_days (current_year)

In this example OpenOffice.org Basic has been used to create and use the Summer Solstice array, but the same technique can easily be adapted to any programming language so that the correct date can be used either in a desktop application or on any web site.

Bibliography

Duncan, David Ewing. The Calendar. London, United Kingdom: Forth Estate, 1998


The copyright of the article The Summer Solstice and the Programmer in Computer Programming is owned by Mark Alexander Bain. Permission to republish The Summer Solstice and the Programmer in print or online must be granted by the author in writing.


A Typical Summer Solstice at Stonehenge, MorgueFile
       


Post this Article to facebook Add this Article to del.icio.us! Digg this Article furl this Article Add this Article to Reddit Add this Article to Technorati Add this Article to Newsvine Add this Article to Windows Live Add this Article to Yahoo Add this Article to StumbleUpon Add this Article to BlinkLists Add this Article to Spurl Add this Article to Google Add this Article to Ask Add this Article to Squidoo