// (C)2007 Attila Kovacs <attila@submm.caltech.edu>



public final class CurrentTime {
	public static double DUT1 = 0.0;
	public static double errorUT1 = 1.0 * Unit.s;
	public static double leap = 33.0 * Unit.s; // As of 1 Jan 2006
	
	private static AstroTime time = new AstroTime();
	
	// Terrestrial Time is based on Atomic Time (not linked to Earth rotation)
	// TT = TAI + 32.184s
	public static synchronized double TT() {
		return time.now().getTT();	
	}
	
	public static synchronized double UTC() {
		return TAI() - leap;
	}
	
	public static synchronized double LST(double longitude) {
		return time.now().getLST(longitude);
	}
	
	// UT1 reflects most correctly the rotational position of Earth (i.e. to be used in astronomy)
	// needs DUT1 lookup from server via refreshData() to be accurate
	public static synchronized double UT1() {
		return UTC() + DUT1;
	}
	
	// UT2 is historical. It smoothes out seasonal variations of UT1
	// UT2 = UT1 + 0.022 sin(2*pi*T) - 0.012 cos(2*pi*T) - 0.006 sin(4*pi*T) + 0.007 cos(4*pi*T)  
	// where T is the date in Besselian years
	public static synchronized double UT2() {
		double UTC = UTC();
		double PIT = Math.PI * UTC / Unit.year;	
		return UTC + (0.022 * Math.sin(2.0*PIT) - 0.012 * Math.cos(2.0*PIT) - 0.006*Math.sin(4.0*PIT) + 0.007*Math.cos(4.0*PIT)) * Unit.s;
	}
	
	
	// TAI is atomic time, thus not linked to Earth's rotation...
	// TAI-UTC(BIPM) = 33.000 000 seconds    
	public static synchronized double TAI() {
		return time.now().getTAI();
	}
	
	// GPS time is the time used for GPS positioning. Based on Atomic time.
	public static synchronized double GPST() {
		return time.now().getGPSTime();
	}
	
	// TCG is based on the Atomic Time but corrects for the gravitational dilation on Earth
	// Thus it is a good measure of time in space.
	// TT = TCG − LG × (JDTCG − 2443144.5003725) × 86400
	// LG = 6.969290134e-10
	public static synchronized double TCG() {
		return time.now().getTCG();
	}
	
	
	static { refreshData(); }
	
	// TODO
	// Contact the www.iers.org for data
	// console error if it's not possible to obtain...
	public static void refreshData() {
		
		
	}
}
