3.4.1.1 Analysis of Julian Day Number to Gregorian date algorithms

This section analyzes the core of various conversion algorithms that convert from the Julian Day Number to a Gregorian Date. Since all of the algorithms that deal with fractional Julian Day Numbers initially remove the fractional part at the beginning of the procedure and account for it at the end of the procedure, this part of the algorithm is ignored. Also excluded is the conversion from a calendar beginning March 1 to a calendar beginning January 1 because the choices available are well known and removal means that the choice between an "if-test" and an arithmetic operation can be ignored. The analysis is further simplified by ignoring the fact that the functions that convert between month number and the number of days in the preceding month can be implemented as an indexed array.

The intent of the following table is to give some idea of the complexity of some of the various implementations that have been presented. The ID numbers reference algorithms in the implementation section. The table shows that the algorithms are roughly comparable in complexity. This means that in order to find the "best" algorithm for the implementation on a particular machine, it is necessary to look more closely at the speed of various operations and the operation of the algorithm a whole. The following section looks at some timing for various implementations using QBASIC on a PC under Microsoft Windows.

Analysis of Julian Day Number to Gregorian Date Algorithms

ID

AUTHOR

TYPE

RANGE

+ -

*

\

/

SHIFT

INT

FIX

1

Baum

Real

All

8

3

2

3

0

4

2

2

Baum

Integer

All

9

5

6

0

0

4

2

3

Baum

Integer

>1721118.25

9

5

2

0

4

0

2

6

Meeus

Real

>1867215.75

11

2

1

3

0

0

6

7

Fliegel

Integer

>0.5

9

7

6

0

0

0

6

 

3.4.1.2 QBASIC Timing of some Julian Day Number to Gregorian date implementations

Routine

Type

Range

Conversions per second

Comments

Baum4

Integer

>1721119

3542.3

No fractional JD allowed

FLIEGEL

Integer

>0.5

3194.0

No fractional JD allowed

BAUM3

Integer

> 1721118.5

2392.3

 

BAUM1

Real

All

1202.6

Tricky Roundup

BAUM2

Real

All

1183.0

 

Meeus

Real

>1867215.75

1010.9

 


SUB baum1 (jd AS DOUBLE, year AS LONG, month AS INTEGER, day AS DOUBLE)
'Baum - real arithmetic with tricky roundup
Z& = INT(jd - 1721118.5#)
R# = jd - 1721118.5# - Z&
G# = Z& - .25#
A& = INT(G# / 36524.25#)
B# = G# + A& - INT(A& / 4#)'days if years were Julian
year = INT((B#) / 365.25#)
C& = B# - INT(365.25 * year) 'B# ends in 0.75 and integer conversion rounds up
month = (5 * C& + 456) \ 153
day = C& - ((153 * month - 457) \ 5) + R#
IF month > 12 THEN
year = year + 1
month = month - 12
END IF
END SUB

SUB baum2 (jd AS DOUBLE, year AS LONG, month AS INTEGER, day AS DOUBLE)
'INPUT: jd = Julian Day Number
'OUTPUT: Gregorian year, month, and day
'standard real arithmetic
Z& = INT(jd - 1721118.5#) 'Day 1 is on March 1 of the year 0
R# = jd - 1721118.5# - Z& 'the fractional part of the day
G# = Z& - .25#
A& = INT(G# / 36524.25#) 'whole centuries
B& = A& - INT(A& / 4#) 'Julian days in whole centuries - 0.25
year = INT((G# + B&) / 365.25#)
C& = Z& + B& - INT(365.25 * year)'days in the year
month = (5 * C& + 456) \ 153
day = C& - ((153 * month - 457) \ 5) + R#
IF month > 12 THEN 'convert to year that starts January 1
year = year + 1
month = month - 12
END IF 'convert to year that starts January 1
END SUB

SUB baum3 (jd AS DOUBLE, year AS LONG, month AS INTEGER, day AS DOUBLE)
'***WARNING*** ONLY VALID IF JD > 1721118.5 (March 1 of day zero)
'INPUT: jd = Julian Day Number
'OUTPUT: Gregorian year, month, and day
'integer arithmetic and integer division in particular
Z& = INT(jd - 1721118.5#) 'Day 1 is on March 1 of the year 0
R# = jd - 1721118.5# - Z& 'the fractional part of the day
H& = 100 * Z& - 25
A& = H& \ 3652425'whole centuries
B& = A& - A& \ 4'adjustment to find the Julian days in whole centuries
year = (100 * B& + H&) \ 36525
C& = B& + Z& - 365 * year - year \ 4'days in the year
month = (5 * C& + 456) \ 153
day = C& - (153 * month - 457) \ 5 + R#
IF month > 12 THEN 'convert to year that starts January 1
year = year + 1
month = month - 12
END IF 'convert to year that starts January 1
END SUB

SUB baum4 (jd AS DOUBLE, year AS LONG, month AS INTEGER, day AS DOUBLE)
'NO FRACTIONAL JULIAN DAY NUMBER ALLOWED
'JULIAN DAY NUMBER MUST BE GREATER THAN 1721119
Z& = jd - 1721119
H& = 100 * Z& - 25
A& = H& \ 3652425
B& = A& - A& \ 4
year = (100 * B& + H&) \ 36525
C& = B& + Z& - 365 * year - year \ 4
month = (5 * C& + 456) \ 153
day = C& - (153 * month - 457) \ 5
IF month > 12 THEN
year = year + 1
month = month - 12
END IF 'convert to year that starts January 1
END SUB

SUB fliegel (jd AS DOUBLE, year AS LONG, month AS INTEGER, day AS DOUBLE)
l& = jd + 68569
n& = (4 * l&) \ 146097
l& = l& - (146097 * n& + 3) \ 4
I& = 4000 * (l& + 1) \ 1461001
l& = l& - (1461 * I&) \ 4 + 31
J& = (80 * l&) \ 2447
day = l& - (2447 * J&) \ 80
l& = J& \ 11
month = J& + 2 - 12 * l&
year = 100 * (n& - 49) + I& + l&
END SUB

SUB meeus (jd AS DOUBLE, year AS LONG, month AS INTEGER, day AS DOUBLE)
'meeus
Z& = INT(jd + .5#)
R# = jd + .5# - Z&
G& = INT((Z& - 1867216.25#) / 36524.25#)
A& = Z& + 1 + G& - INT(G& / 4)
B& = A& + 1524
C& = INT((B& - 122.1#) / 365.25#)
d& = INT(365.25# * C&)
E& = INT((B& - d&) / 30.6001#)
day = B& - d& - INT(30.6001# * E&) + R#
IF E& < 14 THEN
month = E& - 1
ELSE 'E=14 or E=15
month = E& - 13
END IF
IF month > 2 THEN
year = C& - 4716
ELSE
year = C& - 4715 ' M=1 or M=2
END IF
END SUB

3.4.2 Analysis of Julian Day Number to Julian date algorithms

This section analyzes the core of various conversion algorithms that convert from the Julian Day Number to a Julian Date. Since all of the algorithms that deal with fractional Julian Day Numbers initially remove the fractional part at the beginning of the procedure and account for it at the end of the procedure, this part of the algorithm is ignored. Also excluded is the conversion from a calendar beginning March 1 to a calendar beginning January 1 because the choices available are well known and removal means that the choice between an "if-test" and an arithmetic operation can be ignored. The analysis is further simplified by ignoring the fact that the functions that convert between month number and the number of days in the preceding month can be implemented as an indexed array.

 

Analysis of Julian Day Number to Julian Date Algorithms

 

ID

AUTHOR

TYPE

RANGE

+ -

*

\

/

SHIFT

INT

FIX

1

Baum

Real

All

5

3

2

1

0

2

2

2

Baum

Integer

All

6

4

4

0

0

2

2

3

Baum

Integer

>1721118.25

6

4

1

0

3

0

1

6

Meeus

Real

>1867215.75

7

2

0

2

0

0

4


AESIR RESEARCH HOME PAGE

LAST MODIFIED: April 7, 2005