Zeller's congruence

Zeller's congruence

Zeller's congruence is an algorithm devised by Christian Zeller to calculate the day of the week for any Julian or Gregorian calendar date.

Formula

For the Gregorian calendar, Zeller's congruence is

:h = left(q + leftlfloorfrac{(m+1)26}{10} ight floor + K + leftlfloorfrac{K}{4} ight floor + leftlfloorfrac{J}{4} ight floor - 2J ight) mod 7,

for the Julian calendar it is

:h = left(q + leftlfloorfrac{(m+1) 26}{10} ight floor + K + leftlfloorfrac{K}{4} ight floor + 5 - J ight) mod 7,

where
* "h" is the day of the week (0 = Saturday, 1 = Sunday, 2 = Monday, ...
* "q" is the day of the month
* "m" is the month (3 = March, 4 = April, 5 = May, ...)
* "K" the year of the century (year mod 100).
* "J" is the century (actually lfloor year/100 floor)

NOTE: In this algorithm January and February are counted as months 13 and 14 of the previous year.

For an ISO week date Day-of-Week "d" (1 = Monday to 7 = Sunday), use:d = ((h + 5) mod 7) + 1

Implementation in software

The formulas rely on the mathematician's definition of modulo division, which means that −2 mod 7 is equal to positive 5. Unfortunately, the way most computer languages implement the remainder function, −2 mod 7 returns a result of -2. So, to implement Zeller's congruence on a computer, the formulas should be altered slightly to ensure a positive numerator. The simplest way to do this is to replace − 2"J" by + 5"J" and − "J" by + 6"J". So the formulas become:

:h = left(q + leftlfloorfrac{(m+1)26}{10} ight floor + K + leftlfloorfrac{K}{4} ight floor + leftlfloorfrac{J}{4} ight floor + 5J ight) mod 7,

for the Gregorian calendar, and

:h = left(q + leftlfloorfrac{(m+1) 26}{10} ight floor + K + leftlfloorfrac{K}{4} ight floor + 5 + 6J ight) mod 7,

for the Julian calendar.

Zeller used decimal arithmetic, and found it convenient to use "J" & "K" in representing the year. But when using a computer, it is simpler to handle the modified year "Y" by using "Y", "Y div 4", and for Gregorian also "Y div 100" & "Y div 400".

Analysis

These formulas are based on the observation that the day of the week progresses in a predictable manner based upon each subpart of that date. Each term within the formula is used to calculate the offset needed to obtain the correct day of the week.

For the Gregorian calendar, the various parts of this formula can therefore be understood as follows:

*q represents the progression of the day of the week based on the day of the month, since each successive day results in an additional offset of 1 in the day of the week.
*K represents the progression of the day of the week based on the year. Assuming that each year is 365 days long, the same date on each succeeding year will be offset by a value of 365mod 7 = 1.
*Since there are 366 days in each leap year, this needs to be accounted for by adding an additional day to the day of the week offset value. This is accomplished by adding leftlfloorfrac{K}{4} ight floor to the offset. This term is calculated as an integer result. Any remainder is discarded.
*Using similar logic, the progression of the day of the week for each century may be calculated by observing that there are 36524 days in a normal century and 36525 days in each century divisible by 400. Since 36525mod 7 = 6 and 36524mod 7 = 5, the term :leftlfloorfrac{J}{4} ight floor - 2J accounts for this (again using integer division and discarding any fractional remainder). To avoid negative numbers, this term can be replaced with :leftlfloorfrac{J}{4} ight floor + 5J with equivalent results.
*The term leftlfloorfrac{(m+1)26}{10} ight floor can be explained as follows. Zeller observed that, by starting each year on March 1, the day of the week for each succeeding month progressed by multiplying the month by a constant value and discarding the fractional remainder.
*The overall function, mod 7, normalizes the result to reside in the range of 0 to 6, which yields the index of the correct day of the week for the date being analyzed. The reason that the formula differs for the Julian calendar is that this calendar does not have a separate rule for leap centuries and is offset from the Gregorian calendar by a fixed number of days each century.

Since the Gregorian calendar was adopted at different times in different regions of the world, the location of an event is significant in determining the correct day of the week for a date that occurred during this transition period.

The formulae can be used proleptically, but with care for years before Year 0. To accommodate this, one can add a sufficient multiple of 400 Gregorian or 28 Julian years.

Examples

For January 1, 2000, the date would be treated as the 13th month of 1999, so the values would be:

:q = 1:m = 13:K = 99:J = 19

So the formula evaluates as (1 + 36 + 99 + 24 + 4 − 38) mod 7 = 126 mod 7 = 0 = Saturday

(The 36 comes from (13+1)*26/10 = 364/10, truncated to an integer.)

However, for March 1, 2000, the date is treated as the 3rd month of 2000, so the values become

:q = 1:m = 3:K = 0:J = 20

so the formula evaluates as (1 + 10 + 0 + 0 + 5 − 40) mod 7 = −24 mod 7 = 4 = Wednesday

ee also

* Doomsday rule
* ISO week date

References

Each of these four similar imaged papers deals firstly with the day of the week and secondly with the date of Easter Sunday, for the Julian and Gregorian Calendars. The pages link to translations into English.

*
*
*
*

External links

* [http://www.merlyn.demon.co.uk/zeller-c.htm The Calendrical Works of Rektor Chr. Zeller: The Day-of-Week and Easter Formulae] by J R Stockton, near London, UK. Site includes images and translations of the above four papers.
*


Wikimedia Foundation. 2010.

Игры ⚽ Поможем написать реферат

Look at other dictionaries:

  • Congruence — is the state achieved by coming together, the state of agreement. The Latin congruō meaning “I meet together, I agree”. As an abstract term, congruence means similarity between objects. Congruence, as opposed to equivalence or approximation, is a …   Wikipedia

  • Zeller — Zeller, meaning both prisoner and monk in German, is a surname, and may refer to:;People * Adolf Guyer Zeller, a Swiss entrepreneur. * Adrien Zeller, a French politician. * Carl Zeller, an Austrian operetta composer. * Christopher Zeller, a… …   Wikipedia

  • Christian Zeller — Julius Christian Johannes Zeller (24 June 1822, Mühlhausen am Neckar – 31 May 1899, Cannstatt) was a German mathematician. Originally trained in mathematics, geography and theology, in 1874 Zeller became Director of the Seminary in Markgröningen… …   Wikipedia

  • Congruencia de Zeller — La congruencia de Zeller es un algoritmo ideado por Julius Christian Johannes Zeller para calcular el día de la semana de cualquier fecha del calendario. Contenido 1 Fórmula 2 Análisis 3 Algoritmo 3.1 …   Wikipedia Español

  • Christian Zeller — Julius Christian Johannes Zeller (24 juin 1822, Mühlhausen am Neckar – 31 mai 1899, Cannstatt) fut un mathématicien allemand. Son éducation porta d abord sur les mathématiques, la géographie et la théologie. En 1874, Zeller devint directeur de… …   Wikipédia en Français

  • Modular arithmetic — In mathematics, modular arithmetic (sometimes called clock arithmetic) is a system of arithmetic for integers, where numbers wrap around after they reach a certain value the modulus. The Swiss mathematician Leonhard Euler pioneered the modern… …   Wikipedia

  • Calculating the day of the week — This article details various mathematical algorithms to calculate the day of the week for any particular date in the past or future.A typical application is to calculate the day of the week on which someone was born or some other special event… …   Wikipedia

  • Leap year — A leap year (or intercalary year) is a year containing one or more extra days (or, in the case of lunisolar calendars, an extra month) in order to keep the calendar year synchronised with the astronomical or seasonal year. For example, in the… …   Wikipedia

  • Doomsday rule — John Conway, inventor of the Doomsday algorithm The Doomsday rule or Doomsday algorithm is a way of calculating the day of the week of a given date. It provides a perpetual calendar since the Gregorian calendar moves in cycles of 400 years. This… …   Wikipedia

  • List of terms relating to algorithms and data structures — The [http://www.nist.gov/dads/ NIST Dictionary of Algorithms and Data Structures] is a reference work maintained by the U.S. National Institute of Standards and Technology. It defines a large number of terms relating to algorithms and data… …   Wikipedia

Share the article and excerpts

Direct link
Do a right-click on the link above
and select “Copy Link”