getDeltaT function
Returns the value 'Delta T,' in seconds, which relates the Terrestrial Dynamical Time scale to measured Universal Time (and indirectly UTC to TAI before 1972, when leap seconds were introduced).
Delta T = TDT - UT1 = (TAI-UTC) - (UT1-UTC) + 32.184s
Delta T, as of 2002, was about 64.3 s.
For 1620-present, Delta T is calculated using a table of delta T values
determined from historical observations (and published in the Astronomical
Almanac. For dates prior to 1620, approximate polynomial algorithms are
used Chapront, Chapront-Touze & Francou (1997)
.
Because Delta T depends on measured values of the Earth's rotation that result from irregular and complex tidal forces for which accurate predictive models do not exist, the future values of Delta T are crudely estimated. For times in the future relative to the last data point in the _deltaT array, the last delta T value is returned (no reliable predictive models are available and a 'flat line' prediction is as valid as any other. This method will continue to work if additional data is added directly to the _deltaT array.
Implementation
double getDeltaT(TimeInstant time) {
final dt = time.nearestDateTime;
final year = dt.year;
if (year < -391) {
// JPL (used > -3000)
return 31.0 * (year - 1820.0) / 100.0;
} else if (year < 948) {
final u = (year - 2000.0) / 100.0;
return 2177.0 + (497.0 * u) + (44.1 * u * u); // Chapront, Chapront-Touze & Francou (1997)
} else if (year < 1620) {
final u = (year - 2000.0) / 100.0;
return 102.0 + (102.0 * u) + (25.3 * u * u); // Chapront, Chapront-Touze & Francou (1997)
} else {
// Use tables of direct observations and interpolate between years
if (_deltaT == null) _initDeltaT();
final index1 = year - 1620;
final index2 = index1 + 1;
if (index1 > ((_deltaT as List<num>).length - 2)) {
// Out of range... just use the last value (as good a guess as any!)
return ((_deltaT as List<num>)[(_deltaT as List<num>).length - 1]).toDouble();
} else {
final dt1 = (_deltaT as List<num>)[index1];
final dt2 = (_deltaT as List<num>)[index2];
final change = dt2 - dt1;
return (dt1 + time.fractionOfYear * change).toDouble();
}
}
}