JD_UT1 top-level property

TimeInstantUnits JD_UT1
final

Julian Date in the UT1 scale

Implementation

// ignore: non_constant_identifier_names
final TimeInstantUnits JD_UT1 =
    TimeInstantUnits('Julian Date (UT1)', null, 'JD(UT1)', null, 86400.0, false, -2436204.5, (dynamic val) {
  var d = val is num
      ? val.toDouble()
      : val is Number
          ? val.toDouble()
          : 0.0;

  // Find average seconds in day for the year in question
  final deltaT0 = getDeltaT(TimeInstant(TAI: d - 1.57788e7));
  final deltaT1 = getDeltaT(TimeInstant(TAI: d + 1.57788e7));
  final deltaDelta = deltaT1 - deltaT0;
  var secsInDay = 86400.0 + deltaDelta / 365.0;

  // Leap year?
  if (TimeInstant(TAI: d).isLeapYear) secsInDay = 86400.0 + deltaDelta / 366.0;

  d = UT1.fromMks(d).toDouble(); // UTC seconds
  final jd0 = d ~/ 86400; // integer UTC days

  // Fractional UT1 days
  // for the particular UTC day in question
  final frac = (d - (jd0 * 86400.0)) / secsInDay;

  return Double(2436204.5 + jd0 + frac);
}, (dynamic val) {
  var d = val is num
      ? val.toDouble()
      : val is Number
          ? val.toDouble()
          : 0.0;

  // Adjust origin to TAI/UT1 origin
  d -= 2436204.5;

  // Get approximate UT1 (not adjusted for length of day/JD fraction)
  final approxUT1 = d * 86400.0;

  // Find average seconds in day for the year in question
  final deltaT0 = getDeltaT(TimeInstant.inUnits(approxUT1 - 1.57788e7, UT1));
  final deltaT1 = getDeltaT(TimeInstant.inUnits(approxUT1 + 1.57788e7, UT1));
  final deltaDelta = deltaT1 - deltaT0;
  var secsInDay = 86400.0 + deltaDelta / 365.0;

  // Leap year?
  if (TimeInstant(TAI: d).isLeapYear) secsInDay = 86400.0 + deltaDelta / 366.0;

  // Convert to seconds UT1
  final jd0 = d.toInt();
  d = (jd0 * 86400.0) + ((d - jd0) * secsInDay);
  return UT1.toMks(d);
});