Zeller's congruence

Last updated

Zeller's congruence is an algorithm devised by Christian Zeller in the 19th century to calculate the day of the week for any Julian or Gregorian calendar date. It can be considered to be based on the conversion between Julian day and the calendar date.

Contents

Formula

For the Gregorian calendar, Zeller's congruence is

for the Julian calendar it is

where

In this algorithm January and February are counted as months 13 and 14 of the previous year. E.g. if it is 2 February 2010, the algorithm counts the date as the second day of the fourteenth month of 2009 (02/14/2009 in DD/MM/YYYY format)

For an ISO week date Day-of-Week d (1 = Monday to 7 = Sunday), use

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:

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. This is only required through 1929, as this was the last year that the Julian calendar was still in use by any country on earth, and thus is not required for 1930 or later.

The formulae can be used proleptically, but "Year 0" is in fact year 1 BC (see astronomical year numbering). The Julian calendar is in fact proleptic right up to 1 March AD 4 owing to mismanagement in Rome (but not Egypt) in the period since the calendar was put into effect on 1 January 45 BC (which was not a leap year). In addition, the modulo operator might truncate integers to the wrong direction (ceiling instead of floor). To accommodate this, one can add a sufficient multiple of 400 Gregorian or 700 Julian years.

Examples

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

So the formula evaluates as .

(The 36 comes from , truncated to an integer.)

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

so the formula evaluates as .

Implementations in software

Basic modification

The formulas rely on the mathematician's definition of modulo division, which means that −2 mod 7 is equal to positive 5. Unfortunately, in the truncating 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 − 2J with + 5J and J with + 6J.

For the Gregorian calendar, Zeller's congruence becomes

For the Julian calendar, Zeller's congruence becomes


One can readily see that, in a given year, the last day of February and March 1 are a good test dates.

Common simplification

Zeller used decimal arithmetic, and found it convenient to use J and K in representing the year. But when using a computer, it is simpler to handle the modified year Y and month m, which are Y - 1 and m + 12 during January and February:

For the Gregorian calendar, Zeller's congruence becomes

In this case there is no possibility of underflow due to the single negative term because .

For the Julian calendar, Zeller's congruence becomes

The algorithm above is mentioned for the Gregorian case in RFC   3339, Appendix B, albeit in an abridged form that returns 0 for Sunday.

Other variations

At least three other algorithms share the overall structure of Zeller's congruence in its "common simplification" type, also using an m [3, 14] Z and the "modified year" construct.

Both expressions can be shown to progress in a way that is off by one compared to the original month-length component over the required range of m, resulting in a starting value of 0 for Sunday.

See also

Related Research Articles

<span class="mw-page-title-main">Quadratic reciprocity</span> Gives conditions for the solvability of quadratic equations modulo prime numbers

In number theory, the law of quadratic reciprocity is a theorem about modular arithmetic that gives conditions for the solvability of quadratic equations modulo prime numbers. Due to its subtlety, it has many formulations, but the most standard statement is:

<span class="mw-page-title-main">Triangle wave</span> Non-sinusoidal waveform

A triangular wave or triangle wave is a non-sinusoidal waveform named for its triangular shape. It is a periodic, piecewise linear, continuous real function.

<span class="mw-page-title-main">Floor and ceiling functions</span> Nearest integers from a number

In mathematics and computer science, the floor function is the function that takes as input a real number x, and gives as output the greatest integer less than or equal to x, denoted x or floor(x). Similarly, the ceiling function maps x to the least integer greater than or equal to x, denoted x or ceil(x).

In computer programming, a bitwise operation operates on a bit string, a bit array or a binary numeral at the level of its individual bits. It is a fast and simple action, basic to the higher-level arithmetic operations and directly supported by the processor. Most bitwise operations are presented as two-operand instructions where the result replaces one of the input operands.

Dominical letters or Sunday letters are a method used to determine the day of the week for particular dates. When using this method, each year is assigned a letter depending on which day of the week the year starts.

In mathematics a polydivisible number is a number in a given number base with digits abcde... that has the following properties:

  1. Its first digit a is not 0.
  2. The number formed by its first two digits ab is a multiple of 2.
  3. The number formed by its first three digits abc is a multiple of 3.
  4. The number formed by its first four digits abcd is a multiple of 4.
  5. etc.

The determination of the day of the week for any date may be performed with a variety of algorithms. In addition, perpetual calendars require no calculation by the user, and are essentially lookup tables. A typical application is to calculate the day of the week on which someone was born or a specific event occurred.

In number theory, a formula for primes is a formula generating the prime numbers, exactly and without exception. No such formula which is efficiently computable is known. A number of constraints are known, showing what such a "formula" can and cannot be.

<span class="mw-page-title-main">Doomsday rule</span> Way of calculating the day of the week of a given date

The Doomsday rule, Doomsday algorithm or Doomsday method is an algorithm of determination of the day of the week for a given date. It provides a perpetual calendar because the Gregorian calendar moves in cycles of 400 years. The algorithm for mental calculation was devised by John Conway in 1973, drawing inspiration from Lewis Carroll's perpetual calendar algorithm. It takes advantage of each year having a certain day of the week upon which certain easy-to-remember dates, called the doomsdays, fall; for example, the last day of February, 4/4, 6/6, 8/8, 10/10, and 12/12 all occur on the same day of the week in any year.

<span class="mw-page-title-main">Ramanujan tau function</span>

The Ramanujan tau function, studied by Ramanujan (1916), is the function defined by the following identity:

In computing, the modulo operation returns the remainder or signed remainder of a division, after one number is divided by another.

<span class="mw-page-title-main">Josephus problem</span> Mathematical counting-out question

In computer science and mathematics, the Josephus problem is a theoretical problem related to a certain counting-out game. Such games are used to pick out a person from a group, e.g. eeny, meeny, miny, moe.

In number theory, the law of quadratic reciprocity, like the Pythagorean theorem, has lent itself to an unusually large number of proofs. Several hundred proofs of the law of quadratic reciprocity have been published.

The ISO week date system is effectively a leap week calendar system that is part of the ISO 8601 date and time standard issued by the International Organization for Standardization (ISO) since 1988 and, before that, it was defined in ISO (R) 2015 since 1971. It is used (mainly) in government and business for fiscal years, as well as in timekeeping. This was previously known as "Industrial date coding". The system specifies a week year atop the Gregorian calendar by defining a notation for ordinal weeks of the year.

<span class="mw-page-title-main">Ordinal date</span> Date written as number

An ordinal date is a calendar date typically consisting of a year and an ordinal number, ranging between 1 and 366, representing the multiples of a day, called day of the year or ordinal day number. The two parts of the date can be formatted as "YYYY-DDD" to comply with the ISO 8601 ordinal date format. The year may sometimes be omitted, if it is implied by the context; the day may be generalized from integers to include a decimal part representing a fraction of a day.

Cubic reciprocity is a collection of theorems in elementary and algebraic number theory that state conditions under which the congruence x3 ≡ p (mod q) is solvable; the word "reciprocity" comes from the form of the main theorem, which states that if p and q are primary numbers in the ring of Eisenstein integers, both coprime to 3, the congruence x3p is solvable if and only if x3q is solvable.

A calendrical calculation is a calculation concerning calendar dates. Calendrical calculations can be considered an area of applied mathematics. Some examples of calendrical calculations:

In computer science, multiply-with-carry (MWC) is a method invented by George Marsaglia for generating sequences of random integers based on an initial set from two to many thousands of randomly chosen seed values. The main advantages of the MWC method are that it invokes simple computer integer arithmetic and leads to very fast generation of sequences of random numbers with immense periods, ranging from around to .

In number theory, the Fermat quotient of an integer a with respect to an odd prime p is defined as

In modular arithmetic, Barrett reduction is a reduction algorithm introduced in 1986 by P.D. Barrett.

References

  1. The every five months rule only applies to the twelve months of a year commencing on 1 March and ending on the last day of the following February.
  2. 1 2 Stockton, J R. "Material Related to Zeller's Congruence". "Merlyn", archived at NCTU Taiwan.
  3. Tøndering, Claus. "Week-related questions". www.tondering.dk.

Bibliography

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.