6.1 Inverse Rata Die Algorithms

The algorithm development section for converting a Julian Day Number into a Gregorian date justifies most of the following general algorithm forms for converting a Rata Die number into a Gregorian Date. The only modification is in the first step where, since Rata Die day 1 is January 1 of the year 1, the constant 306 is added to convert to the number of days since March 1 of the year 0.

In this description:


STEP 1 Let RD be the Rata Day Number. Calculate

    Z = RD + 306

STEP 2 Calculate the value of A which is the number of full centuries:

STEP 3 Calculate the days within the whole centuries (in the Julian Calendar) by adding back days removed in the Gregorian Calendar. The value of B is this number of days minus a constant.

STEP 4 Calculate the value of Y, the year in a calendar whose years start on March 1:

STEP 5 Calculate the value of the day count in the current year using ONE of the following:

  1. C = Z + A - INT(A/4) - INT(365.25*Y)
  2. C = FIX(B - INT(365.25*Y)) + 1
    This form especially convenient in languages where the assignment of a real to an integer rounds up because B and therefore (B - INT(365.25*Y)) always have a fractional part of 0.75 or greater. In such languages,

    C = B - INT(365.25*Y)
    where C is an integer and B is a real.

STEP 6 Calculate the value of the month in the current year using ONE of the following:

  1. M = FIX((5*C + 456)/ 153)

  2. M = FIX((535*C + 48950)/ 16384)

    (Note that 16384 is 2^14 and the division can be implemented with shifts if the number has a binary representation.)

  3. M = FIX((2140*C + 195800)/ 65536)

    (Note that 65536 is 2^16 and the can be implemented by taking the upper 16 bits of a 32 bit number.)

  4. M = FIX(K3*C+9.333333333333469 - K3 * 194.3333333333375)

    where K3 = .0326530612244898 to 0.03271028037383177

STEP 7 Calculate the value of F, which is the number of days in the preceding months in the current year, using ONE of the following methods:

  1. F is the value of a vector indexed by M. This vector has values 0, 31, 61, 92, 122, 153, 184, 214, 245, 275, 306, 337. (M has values that range from 3 through 14.) This method is usually the fastest method and often takes less computer memory to implement.

  2. F = (153*M-457)\5

  3. F = (979*M-2918)\32
    This allows a shift to carry out the division.

  4. If real arithmetic is desired,
    F=FIX(30.6*M-91.4) = -122+FIX(30.6*(M+1))
    can be used although real arithmetic is usually slower and takes more code space. Other coefficients are possible as described in the previous section. Note that since M is 3 or greater, 30.6*M-91.4 is always positive. Either FIX or the greatest integer function can be used.

STEP 8 The Gregorian date's day of the month is

STEP 9 Convert the month and year to a calendar starting January 1, using ONE of the following methods:

This calculation is valid for any Rata Die number including negative Rata Die numbers and produces a Gregorian date (or possibly a proleptic Gregorian date).

Example

The following sequence calculates Gregorian year Y, month M, and day D from a Rata Die number:

Z = RD + 306 step 1
G = Z - .25 used in later steps
A = INT(G / 36524.25) step 2
B = A - INT(A / 4) part of step 3
year = INT((B+G) / 365.25) part of step 3 and step 4
C = B + Z - INT(365.25 * year) step 5
month = FIX((5 * C + 456) / 153) step 6
day = C - FIX((153 * month - 457) / 5)step 7 and 8
IF month > 12 THENstep 9
       year = year + 1step 9
       month = month - 12step 9
END IFstep 9


AESIR RESEARCH HOME PAGE

LAST MODIFIED: July 9, 2007