summaryrefslogtreecommitdiffstats
path: root/org/madore/ephem/Time.java
blob: 3d2cb3e8a1aefe540089a1dde45ca649e33cefbc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package org.madore.ephem;

public final class Time {

    public static final class LeapSecond {
	public int mjd;
	public int offset;
	public LeapSecond(int mjd, int offset) {
	    this.mjd = mjd;
	    this.offset = offset;
	}
    }

    public static final LeapSecond[] leapSecondsTable = new LeapSecond[] {
	new LeapSecond(41317, 10),
	new LeapSecond(41499, 11),
	new LeapSecond(41683, 12),
	new LeapSecond(42048, 13),
	new LeapSecond(42413, 14),
	new LeapSecond(42778, 15),
	new LeapSecond(43144, 16),
	new LeapSecond(43509, 17),
	new LeapSecond(43874, 18),
	new LeapSecond(44239, 19),
	new LeapSecond(44786, 20),
	new LeapSecond(45151, 21),
	new LeapSecond(45516, 22),
	new LeapSecond(46247, 23),
	new LeapSecond(47161, 24),
	new LeapSecond(47892, 25),
	new LeapSecond(48257, 26),
	new LeapSecond(48804, 27),
	new LeapSecond(49169, 28),
	new LeapSecond(49534, 29),
	new LeapSecond(50083, 30),
	new LeapSecond(50630, 31),
	new LeapSecond(51179, 32),
	new LeapSecond(53736, 33),
	new LeapSecond(54832, 34),
	new LeapSecond(56109, 35),
    };

    public static double utcToTt(int utcMjd, double utcSeconds) {
	// Returns JD in TT
	int i0 = 0;  int i1 = leapSecondsTable.length;
	while ( i1-i0 > 1 ) {
	    int i = (i0+i1)/2;
	    if ( utcMjd >= leapSecondsTable[i].mjd )
		i0 = i;
	    else
		i1 = i;
	}
	return ( utcSeconds + leapSecondsTable[i0].offset + 32.184 )/86400. + utcMjd + 2400000.5;
    }

}