|
||||||
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 SolsticeIt 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:
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 ProgramIt 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. BibliographyDuncan, 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.
|
||||||
|
|
||||||
|
|
||||||