diff --git a/JulianDates.cs b/JulianDates.cs index 76ccec3..f92ca9d 100644 --- a/JulianDates.cs +++ b/JulianDates.cs @@ -3,609 +3,653 @@ namespace JulianAndHisDates { - /// - /// JulianDates - /// - public static class JulianDates - { - #region consonants - - /// - /// Julian Date coefficient - /// - private const double doubleJulianDateCoefficient = 2415018.5; - - /// - /// Modified Julian Date coefficient - /// - private const double doubleModifiedJulianDateCoefficient = 2400000.5; - - /// - /// Reduced Julian Date coefficient - /// - private const double doubleReducedJulianDateCoefficient = 2400000; - - /// - /// Truncated Julian Date coefficient - /// - private const double doubleTruncatedJulianDateCoefficient = 2440000.5; - - /// - /// Dublin Julian Date coefficient - /// - private const double doubleDublinJulianDateCoefficient = 2415020; - - /// - /// CCNES Julian Date coefficient - /// - private const double doubleCnesJulianDateCoefficient = 2433282.5; - - /// - /// CCSDS Julian Date coefficient - /// - private const double doubleCcsdsJulianDateCoefficient = 2436204.5; - - /// - /// LOP Julian Date coefficient - /// - private const double doubleLopJulianDateCoefficient = 2448622.5; - - /// - /// Millenium Julian Date coefficient - /// - private const double doubleMillenniumJulianDateCoefficient = 2451544.5; - - /// - /// Lilian Date coefficient - /// - private const double doubleLilianDateCoefficient = 2299159.5; - - /// - /// Rata Die coefficient - /// - private const double doubleRataDieCoefficient = 1721424.5; - - /// - /// Mars Sol Date coefficient - /// - private const double doubleMarsSolDateCoefficient = 2405522; - - /// - /// ratio of the rotation of Earth and Mars - /// - private const double doubleRatioRotationAxisEarthMars = 1.02749; - - /// - /// Unix Time coefficient - /// - private const double doubleUnixtimeCoefficient = 2440587.5; - - /// - /// seconds in a day - /// - private const int secondsOfDay = 86400; - - #endregion - - #region JD Calculators - - /// - /// Calculate the Julian Date from the Universal time - /// - /// Julian Date - public static double CalculateJulianDate() => DateTime.Now.ToUniversalTime().ToOADate() + doubleJulianDateCoefficient; - - /// - /// Calculate the Julian Date from the date - /// - /// date - /// Julian Date - public static double CalculateJulianDate(DateTime date) => date.ToOADate() + doubleJulianDateCoefficient; - - /// - /// Calculate the Modified Julian Date - /// - /// Modified Julian Date - public static double CalculateModifiedJulianDate() => CalculateJulianDate() - doubleModifiedJulianDateCoefficient; - - /// - /// Calculate the Modified Julian Date from the date - /// - /// date - /// Modified Julian Date - public static double CalculateModifiedJulianDate(DateTime date) => CalculateJulianDate(date: date) - doubleModifiedJulianDateCoefficient; - - /// - /// Calculate the Modified Julian Date from the Julian Date - /// - /// Julian Date - /// Modified Julian Date - public static double CalculateModifiedJulianDate(double julianDate) => julianDate - doubleModifiedJulianDateCoefficient; - - /// - /// Calculate the Reduced Julian Date - /// - /// Reduced Julian Date - public static double CalculateReducedJulianDate() => CalculateJulianDate() - doubleReducedJulianDateCoefficient; - - /// - /// Calculate the Reduced Julian Date from the date - /// - /// date - /// Reduced Julian Date - public static double CalculateReducedJulianDate(DateTime date) => CalculateJulianDate(date: date) - doubleReducedJulianDateCoefficient; - - /// - /// Calculate the Reduced Julian Date from the Julian Date - /// - /// Julian Date - /// Reduced Julian Date - public static double CalculateReducedJulianDate(double julianDate) => julianDate - doubleReducedJulianDateCoefficient; - - /// - /// Calculate the Truncated Julian Date - /// - /// Truncated Hulian Date - public static double CalculateTruncatedJulianDate() => Math.Floor(CalculateJulianDate() - doubleTruncatedJulianDateCoefficient); - - /// - /// Calculate the Truncated Julian Date from the date - /// - /// date - /// Truncated Hulian Date - public static double CalculateTruncatedJulianDate(DateTime date) => Math.Floor(CalculateJulianDate(date: date) - doubleTruncatedJulianDateCoefficient); - - /// - /// Calculate the Truncated Julian Date from the Julian Date - /// - /// Julian Date - /// Truncated Hulian Date - public static double CalculateTruncatedJulianDate(double julianDate) => Math.Floor(julianDate - doubleTruncatedJulianDateCoefficient); - - /// - /// Calculate the Dublin Julian Date - /// - /// Dublin Julian Date - public static double CalculateDublinJulianDate() => CalculateJulianDate() - doubleDublinJulianDateCoefficient; - - /// - /// Calculate the Dublin Julian Date from the date - /// - /// - /// Dublin Julian Date - public static double CalculateDublinJulianDate(DateTime date) => CalculateJulianDate(date: date) - doubleDublinJulianDateCoefficient; - - /// - /// Calculate the Dublin Julian Date from the Julian Date - /// - /// - /// Dublin Julian Date - public static double CalculateDublinJulianDate(double julianDate) => julianDate - doubleDublinJulianDateCoefficient; - - /// - /// Calculate the CNES Julian Date - /// - /// CNES Julian Date - public static double CalculateCnesJulianDate() => CalculateJulianDate() - doubleCnesJulianDateCoefficient; - - /// - /// Calculate the CNES Julian Date from the date - /// - /// date - /// CNES Julian Date - public static double CalculateCnesJulianDate(DateTime date) => CalculateJulianDate(date: date) - doubleCnesJulianDateCoefficient; - - /// - /// Calculate the CNES Julian Date from the Julian Date - /// - /// Julian Date - /// CNES Julian Date - public static double CalculateCnesJulianDate(double julianDate) => julianDate - doubleCnesJulianDateCoefficient; - - /// - /// Calculate the CCSDS Julian Date - /// - /// CCSDS Julian Date - public static double CalculateCcsdsJulianDate() => CalculateJulianDate() - doubleCcsdsJulianDateCoefficient; - - /// - /// Calculate the CCSDS Julian Date from the date - /// - /// date - /// CCSDS Julian Date - public static double CalculateCcsdsJulianDate(DateTime date) => CalculateJulianDate(date: date) - doubleCcsdsJulianDateCoefficient; - - /// - /// Calculate the CCSDS Julian Date from the Julian Date - /// - /// Julian Date - /// CCSDS Julian Date - public static double CalculateCcsdsJulianDate(double julianDate) => julianDate - doubleCcsdsJulianDateCoefficient; - - /// - /// Calculate the LOP Julian Date - /// - /// LOP Julian Date - public static double CalculateLopJulianDate() => CalculateJulianDate() - doubleLopJulianDateCoefficient; - - /// - /// Calculate the LOP Julian Date from the date - /// - /// date - /// LOP Julian Date - public static double CalculateLopJulianDate(DateTime date) => CalculateJulianDate(date: date) - doubleLopJulianDateCoefficient; - - /// - /// Calculate the LOP Julian Date from the Julian Date - /// - /// Julian Date - /// - /// LOP Julian Date - public static double CalculateLopJulianDate(double julianDate) => julianDate - doubleLopJulianDateCoefficient; - - /// - /// Calculate the Millenium Julian Date - /// - /// Millenium Julian Date - public static double CalculateMillenniumJulianDate() => CalculateJulianDate() - doubleMillenniumJulianDateCoefficient; - - /// - /// Calculate the Millenium Julian Date from the date - /// - /// date - /// Millenium Julian Date - public static double CalculateMillenniumJulianDate(DateTime date) => CalculateJulianDate(date: date) - doubleMillenniumJulianDateCoefficient; - - /// - /// Calculate the Millenium Julian Date from the Julian Date - /// - /// Julian Date - /// Millenium Julian Date - public static double CalculateMillenniumJulianDate(double julianDate) => julianDate - doubleMillenniumJulianDateCoefficient; - - /// - /// Calculate the Chronological Julian Date - /// - /// Chronological Julian Date - public static double CalculateChronologicalJulianDate() - { - TimeZone zone = TimeZone.CurrentTimeZone; - DaylightTime time = zone.GetDaylightChanges(year: DateTime.Today.Year); - //System.Windows.Forms.MessageBox.Show((time.Delta.Hours * (24 / 100)).ToString()); - //double a = time.Delta.Hours / 24.0; - return CalculateJulianDate() + 0.5 + (time.Delta.Hours / 24.0); - } - - /// - /// Calculate the Chronological Julian Date from the date - /// - /// date - /// Chronological Julian Date - public static double CalculateChronologicalJulianDate(DateTime date) - { - TimeZone zone = TimeZone.CurrentTimeZone; - DaylightTime time = zone.GetDaylightChanges(year: DateTime.Today.Year); - return CalculateJulianDate(date: date) + 0.5 + (time.Delta.Hours / 24.0); - } - - /// - /// Calculate the Chronological Julian Date from the Julian Date - /// - /// Julian Date - /// Chronological Julian Date - public static double CalculateChronologicalJulianDate(double julianDate) - { - TimeZone zone = TimeZone.CurrentTimeZone; - DaylightTime time = zone.GetDaylightChanges(year: DateTime.Today.Year); - return julianDate + 0.5 + (time.Delta.Hours / 24.0); - } - - /// - /// Calculate the Chronological Modified Julian Date - /// - /// Chronological Modified Julian Date - public static double CalculateChronologicalModifiedJulianDate() - { - TimeZone zone = TimeZone.CurrentTimeZone; - DaylightTime time = zone.GetDaylightChanges(year: DateTime.Today.Year); - //System.Windows.Forms.MessageBox.Show((time.Delta.Hours * (24 / 100)).ToString()); - //double a = time.Delta.Hours / 24.0; - return CalculateJulianDate() - doubleModifiedJulianDateCoefficient + 0.5 + (time.Delta.Hours / 24.0); - } - - /// - /// Calculate the Chronological Modified Julian Date from the date - /// - /// date - /// Chronological Modified Julian Date - public static double CalculateChronologicalModifiedJulianDate(DateTime date) - { - TimeZone zone = TimeZone.CurrentTimeZone; - DaylightTime time = zone.GetDaylightChanges(year: DateTime.Today.Year); - return CalculateJulianDate(date: date) - doubleModifiedJulianDateCoefficient + 0.5 + (time.Delta.Hours / 24.0); - } - - /// - /// Calculate the Chronological Modified Julian Date from the Julian Date - /// - /// Julian Date - /// Chronological Modified Julian Date - public static double CalculateChronologicalModifiedJulianDate(double julianDate) - { - TimeZone zone = TimeZone.CurrentTimeZone; - DaylightTime time = zone.GetDaylightChanges(year: DateTime.Today.Year); - return julianDate - doubleModifiedJulianDateCoefficient + 0.5 + (time.Delta.Hours / 24.0); - } - - /// - /// Calculate the Lilian Date - /// - /// Lilian Date - public static double CalculateLilianDate() => Math.Floor(d: CalculateJulianDate() - doubleLilianDateCoefficient); - - /// - /// Calculate the Lilian Date from the date - /// - /// date - /// Lilian Date - public static double CalculateLilianDate(DateTime date) => Math.Floor(d: CalculateJulianDate(date: date) - doubleLilianDateCoefficient); - - /// - /// Calculate the Lilian Date from the Julian Date - /// - /// Julian Date - /// Lilian Date - public static double CalculateLilianDate(double julianDate) => Math.Floor(d: julianDate - doubleLilianDateCoefficient); - - /// - /// Calculate the Rata Die - /// - /// Rata Die - public static double CalculateRataDie() => Math.Floor(d: CalculateJulianDate() - doubleRataDieCoefficient); - - /// - /// Calculate the Rata Die from the date - /// - /// date - /// Rata Die - public static double CalculateRataDie(DateTime date) => Math.Floor(d: CalculateJulianDate(date: date) - doubleRataDieCoefficient); - - /// - /// Calculate the Rata Die from the Julian Date - /// - /// Julian Date - /// Rata Die - public static double CalculateRataDie(double julianDate) => Math.Floor(d: julianDate - doubleRataDieCoefficient); - - /// - /// Calculate the Mars Sol Date - /// - /// Mars Sol Date - public static double CalculateMarsSolDate() => (CalculateJulianDate() - doubleMarsSolDateCoefficient) / doubleRatioRotationAxisEarthMars; - - /// - /// Calculate the Mars Sol Date from the date - /// - /// date - /// Mars Sol Date - public static double CalculateMarsSolDate(DateTime date) => (CalculateJulianDate(date: date) - doubleMarsSolDateCoefficient) / doubleRatioRotationAxisEarthMars; - - /// - /// Calculate the Mars Sol Date from the Julian Date - /// - /// Julian Date - /// Mars Sol Date - public static double CalculateMarsSolDate(double julianDate) => (julianDate - doubleMarsSolDateCoefficient) / doubleRatioRotationAxisEarthMars; - - /// - /// Calculate the Unix Time - /// - /// Unix Time - public static double CalculateUnixTime() => (CalculateJulianDate() - doubleUnixtimeCoefficient) * secondsOfDay; - - /// - /// Calculate the Unix Time from the date - /// - /// date - /// Unix Time - public static double CalculateUnixTime(DateTime date) => (CalculateJulianDate(date: date) - doubleUnixtimeCoefficient) * secondsOfDay; - - /// - /// Calculate the Unix Time from the Julian Date - /// - /// Julian Date - /// Unix Time - public static double CalculateUnixTime(double julianDate) => (julianDate - doubleUnixtimeCoefficient) * secondsOfDay; - - #endregion - - #region JD Converters - - /// - /// Convert Julian Date to civil calendar - /// - /// Julian Date - /// civil calendar - public static DateTime ConvertJulianDateToCivilCalendar(double julianDate) - { - double j = julianDate; - double intgr = Math.Floor(d: j); - double frac = j - intgr; - const double gregjd = 2299160.5; - double j1; - if (j >= gregjd) - { - double tmp = Math.Floor(d: (intgr - 1867216.0 - 0.25) / 36524.25); - j1 = intgr + 1 + tmp - Math.Floor(d: 0.25 * tmp); - } - else - { - j1 = intgr; - } - double df = frac + 0.5; - if (df >= 1.0) - { - df--; - ++j1; - } - double j2 = j1 + 1524.0; - double j3 = Math.Floor(d: 6680.0 + ((j2 - 2439870.0 - 122.1) / 365.25)); - double j4 = Math.Floor(d: j3 * 365.25); - double j5 = Math.Floor(d: (j2 - j4) / 30.6001); - double d = Math.Floor(d: j2 - j4 - Math.Floor(d: j5 * 30.6001)); - double m = Math.Floor(d: j5 - 1.0); - if (m > 12) - { - m -= 12; - } - double y = Math.Floor(d: j3 - 4715.0); - if (m > 2) - { - --y; - } - if (y <= 0) - { - --y; - } - double d1 = df * 24.0; - double hr = Math.Floor(d: d1); - double mn = Math.Floor(d: ((df * 24.0) - hr) * 60.0); - double f = ((((df * 24.0) - hr) * 60.0) - mn) * 60.0; - double sc = Math.Floor(d: f); - f -= sc; - if (f > 0.5) - { - ++sc; - } - if (sc == 60) - { - sc = 0; - ++mn; - } - if (mn == 60) - { - mn = 0; - ++hr; - } - if (hr == 24) - { - hr = 0; - ++d; - } - /*if (y < 0) + /// + /// JulianDates + /// + public static class JulianDates + { + #region consonants + + /// + /// Julian Date coefficient + /// + private const double doubleJulianDateCoefficient = 2415018.5; + + /// + /// Modified Julian Date coefficient + /// + private const double doubleModifiedJulianDateCoefficient = 2400000.5; + + /// + /// Reduced Julian Date coefficient + /// + private const double doubleReducedJulianDateCoefficient = 2400000; + + /// + /// Truncated Julian Date coefficient + /// + private const double doubleTruncatedJulianDateCoefficient = 2440000.5; + + /// + /// Dublin Julian Date coefficient + /// + private const double doubleDublinJulianDateCoefficient = 2415020; + + /// + /// CCNES Julian Date coefficient + /// + private const double doubleCnesJulianDateCoefficient = 2433282.5; + + /// + /// CCSDS Julian Date coefficient + /// + private const double doubleCcsdsJulianDateCoefficient = 2436204.5; + + /// + /// LOP Julian Date coefficient + /// + private const double doubleLopJulianDateCoefficient = 2448622.5; + + /// + /// Millenium Julian Date coefficient + /// + private const double doubleMillenniumJulianDateCoefficient = 2451544.5; + + /// + /// Lilian Date coefficient + /// + private const double doubleLilianDateCoefficient = 2299159.5; + + /// + /// Rata Die coefficient + /// + private const double doubleRataDieCoefficient = 1721424.5; + + /// + /// Mars Sol Date coefficient + /// + private const double doubleMarsSolDateCoefficient = 2405522; + + /// + /// ratio of the rotation of Earth and Mars + /// + private const double doubleRatioRotationAxisEarthMars = 1.02749; + + /// + /// Unix Time coefficient + /// + private const double doubleUnixtimeCoefficient = 2440587.5; + + /// + /// seconds in a day + /// + private const int secondsOfDay = 86400; + #endregion + + #region JD Calculators + + /// + /// Calculate the Julian Date from the Universal time + /// + /// Julian Date + public static double CalculateJulianDate() => DateTime.Now.ToUniversalTime().ToOADate() + + doubleJulianDateCoefficient; + + /// + /// Calculate the Julian Date from the date + /// + /// date + /// Julian Date + public static double CalculateJulianDate(DateTime date) => date.ToOADate() + doubleJulianDateCoefficient; + + /// + /// Calculate the Modified Julian Date + /// + /// Modified Julian Date + public static double CalculateModifiedJulianDate() => CalculateJulianDate() - + doubleModifiedJulianDateCoefficient; + + /// + /// Calculate the Modified Julian Date from the date + /// + /// date + /// Modified Julian Date + public static double CalculateModifiedJulianDate(DateTime date) => CalculateJulianDate(date: date) - + doubleModifiedJulianDateCoefficient; + + /// + /// Calculate the Modified Julian Date from the Julian Date + /// + /// Julian Date + /// Modified Julian Date + public static double CalculateModifiedJulianDate(double julianDate) => julianDate - + doubleModifiedJulianDateCoefficient; + + /// + /// Calculate the Reduced Julian Date + /// + /// Reduced Julian Date + public static double CalculateReducedJulianDate() => CalculateJulianDate() - doubleReducedJulianDateCoefficient; + + /// + /// Calculate the Reduced Julian Date from the date + /// + /// date + /// Reduced Julian Date + public static double CalculateReducedJulianDate(DateTime date) => CalculateJulianDate(date: date) - + doubleReducedJulianDateCoefficient; + + /// + /// Calculate the Reduced Julian Date from the Julian Date + /// + /// Julian Date + /// Reduced Julian Date + public static double CalculateReducedJulianDate(double julianDate) => julianDate - + doubleReducedJulianDateCoefficient; + + /// + /// Calculate the Truncated Julian Date + /// + /// Truncated Hulian Date + public static double CalculateTruncatedJulianDate() => Math.Floor( + d: CalculateJulianDate() - doubleTruncatedJulianDateCoefficient); + + /// + /// Calculate the Truncated Julian Date from the date + /// + /// date + /// Truncated Hulian Date + public static double CalculateTruncatedJulianDate(DateTime date) => Math.Floor( + d: CalculateJulianDate(date: date) - doubleTruncatedJulianDateCoefficient); + + /// + /// Calculate the Truncated Julian Date from the Julian Date + /// + /// Julian Date + /// Truncated Hulian Date + public static double CalculateTruncatedJulianDate(double julianDate) => Math.Floor( + d: julianDate - doubleTruncatedJulianDateCoefficient); + + /// + /// Calculate the Dublin Julian Date + /// + /// Dublin Julian Date + public static double CalculateDublinJulianDate() => CalculateJulianDate() - doubleDublinJulianDateCoefficient; + + /// + /// Calculate the Dublin Julian Date from the date + /// + /// + /// Dublin Julian Date + public static double CalculateDublinJulianDate(DateTime date) => CalculateJulianDate(date: date) - + doubleDublinJulianDateCoefficient; + + /// + /// Calculate the Dublin Julian Date from the Julian Date + /// + /// + /// Dublin Julian Date + public static double CalculateDublinJulianDate(double julianDate) => julianDate - + doubleDublinJulianDateCoefficient; + + /// + /// Calculate the CNES Julian Date + /// + /// CNES Julian Date + public static double CalculateCnesJulianDate() => CalculateJulianDate() - doubleCnesJulianDateCoefficient; + + /// + /// Calculate the CNES Julian Date from the date + /// + /// date + /// CNES Julian Date + public static double CalculateCnesJulianDate(DateTime date) => CalculateJulianDate(date: date) - + doubleCnesJulianDateCoefficient; + + /// + /// Calculate the CNES Julian Date from the Julian Date + /// + /// Julian Date + /// CNES Julian Date + public static double CalculateCnesJulianDate(double julianDate) => julianDate - doubleCnesJulianDateCoefficient; + + /// + /// Calculate the CCSDS Julian Date + /// + /// CCSDS Julian Date + public static double CalculateCcsdsJulianDate() => CalculateJulianDate() - doubleCcsdsJulianDateCoefficient; + + /// + /// Calculate the CCSDS Julian Date from the date + /// + /// date + /// CCSDS Julian Date + public static double CalculateCcsdsJulianDate(DateTime date) => CalculateJulianDate(date: date) - + doubleCcsdsJulianDateCoefficient; + + /// + /// Calculate the CCSDS Julian Date from the Julian Date + /// + /// Julian Date + /// CCSDS Julian Date + public static double CalculateCcsdsJulianDate(double julianDate) => julianDate - + doubleCcsdsJulianDateCoefficient; + + /// + /// Calculate the LOP Julian Date + /// + /// LOP Julian Date + public static double CalculateLopJulianDate() => CalculateJulianDate() - doubleLopJulianDateCoefficient; + + /// + /// Calculate the LOP Julian Date from the date + /// + /// date + /// LOP Julian Date + public static double CalculateLopJulianDate(DateTime date) => CalculateJulianDate(date: date) - + doubleLopJulianDateCoefficient; + + /// + /// Calculate the LOP Julian Date from the Julian Date + /// + /// Julian Date + /// + /// LOP Julian Date + public static double CalculateLopJulianDate(double julianDate) => julianDate - doubleLopJulianDateCoefficient; + + /// + /// Calculate the Millenium Julian Date + /// + /// Millenium Julian Date + public static double CalculateMillenniumJulianDate() => CalculateJulianDate() - + doubleMillenniumJulianDateCoefficient; + + /// + /// Calculate the Millenium Julian Date from the date + /// + /// date + /// Millenium Julian Date + public static double CalculateMillenniumJulianDate(DateTime date) => CalculateJulianDate(date: date) - + doubleMillenniumJulianDateCoefficient; + + /// + /// Calculate the Millenium Julian Date from the Julian Date + /// + /// Julian Date + /// Millenium Julian Date + public static double CalculateMillenniumJulianDate(double julianDate) => julianDate - + doubleMillenniumJulianDateCoefficient; + + /// + /// Calculate the Chronological Julian Date + /// + /// Chronological Julian Date + public static double CalculateChronologicalJulianDate() + { + TimeZone zone = TimeZone.CurrentTimeZone; + DaylightTime time = zone.GetDaylightChanges(year: DateTime.Today.Year); + //System.Windows.Forms.MessageBox.Show((time.Delta.Hours * (24 / 100)).ToString()); + //double a = time.Delta.Hours / 24.0; + return CalculateJulianDate() + 0.5 + (time.Delta.Hours / 24.0); + } + + /// + /// Calculate the Chronological Julian Date from the date + /// + /// date + /// Chronological Julian Date + public static double CalculateChronologicalJulianDate(DateTime date) + { + TimeZone zone = TimeZone.CurrentTimeZone; + DaylightTime time = zone.GetDaylightChanges(year: DateTime.Today.Year); + return CalculateJulianDate(date: date) + 0.5 + (time.Delta.Hours / 24.0); + } + + /// + /// Calculate the Chronological Julian Date from the Julian Date + /// + /// Julian Date + /// Chronological Julian Date + public static double CalculateChronologicalJulianDate(double julianDate) + { + TimeZone zone = TimeZone.CurrentTimeZone; + DaylightTime time = zone.GetDaylightChanges(year: DateTime.Today.Year); + return julianDate + 0.5 + (time.Delta.Hours / 24.0); + } + + /// + /// Calculate the Chronological Modified Julian Date + /// + /// Chronological Modified Julian Date + public static double CalculateChronologicalModifiedJulianDate() + { + TimeZone zone = TimeZone.CurrentTimeZone; + DaylightTime time = zone.GetDaylightChanges(year: DateTime.Today.Year); + //System.Windows.Forms.MessageBox.Show((time.Delta.Hours * (24 / 100)).ToString()); + //double a = time.Delta.Hours / 24.0; + return CalculateJulianDate() - doubleModifiedJulianDateCoefficient + 0.5 + (time.Delta.Hours / 24.0); + } + + /// + /// Calculate the Chronological Modified Julian Date from the date + /// + /// date + /// Chronological Modified Julian Date + public static double CalculateChronologicalModifiedJulianDate(DateTime date) + { + TimeZone zone = TimeZone.CurrentTimeZone; + DaylightTime time = zone.GetDaylightChanges(year: DateTime.Today.Year); + return CalculateJulianDate(date: date) - + doubleModifiedJulianDateCoefficient + + 0.5 + (time.Delta.Hours / 24.0); + } + + /// + /// Calculate the Chronological Modified Julian Date from the Julian Date + /// + /// Julian Date + /// Chronological Modified Julian Date + public static double CalculateChronologicalModifiedJulianDate(double julianDate) + { + TimeZone zone = TimeZone.CurrentTimeZone; + DaylightTime time = zone.GetDaylightChanges(year: DateTime.Today.Year); + return julianDate - doubleModifiedJulianDateCoefficient + 0.5 + (time.Delta.Hours / 24.0); + } + + /// + /// Calculate the Lilian Date + /// + /// Lilian Date + public static double CalculateLilianDate() => Math.Floor(d: CalculateJulianDate() - doubleLilianDateCoefficient); + + /// + /// Calculate the Lilian Date from the date + /// + /// date + /// Lilian Date + public static double CalculateLilianDate(DateTime date) => Math.Floor( + d: CalculateJulianDate(date: date) - doubleLilianDateCoefficient); + + /// + /// Calculate the Lilian Date from the Julian Date + /// + /// Julian Date + /// Lilian Date + public static double CalculateLilianDate(double julianDate) => Math.Floor( + d: julianDate - doubleLilianDateCoefficient); + + /// + /// Calculate the Rata Die + /// + /// Rata Die + public static double CalculateRataDie() => Math.Floor(d: CalculateJulianDate() - doubleRataDieCoefficient); + + /// + /// Calculate the Rata Die from the date + /// + /// date + /// Rata Die + public static double CalculateRataDie(DateTime date) => Math.Floor( + d: CalculateJulianDate(date: date) - doubleRataDieCoefficient); + + /// + /// Calculate the Rata Die from the Julian Date + /// + /// Julian Date + /// Rata Die + public static double CalculateRataDie(double julianDate) => Math.Floor(d: julianDate - doubleRataDieCoefficient); + + /// + /// Calculate the Mars Sol Date + /// + /// Mars Sol Date + public static double CalculateMarsSolDate() => (CalculateJulianDate() - doubleMarsSolDateCoefficient) / + doubleRatioRotationAxisEarthMars; + + /// + /// Calculate the Mars Sol Date from the date + /// + /// date + /// Mars Sol Date + public static double CalculateMarsSolDate(DateTime date) => (CalculateJulianDate(date: date) - + doubleMarsSolDateCoefficient) / doubleRatioRotationAxisEarthMars; + + /// + /// Calculate the Mars Sol Date from the Julian Date + /// + /// Julian Date + /// Mars Sol Date + public static double CalculateMarsSolDate(double julianDate) => (julianDate - doubleMarsSolDateCoefficient) / + doubleRatioRotationAxisEarthMars; + + /// + /// Calculate the Unix Time + /// + /// Unix Time + public static double CalculateUnixTime() => (CalculateJulianDate() - doubleUnixtimeCoefficient) * secondsOfDay; + + /// + /// Calculate the Unix Time from the date + /// + /// date + /// Unix Time + public static double CalculateUnixTime(DateTime date) => (CalculateJulianDate(date: date) - + doubleUnixtimeCoefficient) * secondsOfDay; + + /// + /// Calculate the Unix Time from the Julian Date + /// + /// Julian Date + /// Unix Time + public static double CalculateUnixTime(double julianDate) => (julianDate - doubleUnixtimeCoefficient) * + secondsOfDay; + #endregion + + #region JD Converters + + /// + /// Convert Julian Date to civil calendar + /// + /// Julian Date + /// civil calendar + public static DateTime ConvertJulianDateToCivilCalendar(double julianDate) + { + double j = julianDate; + double intgr = Math.Floor(d: j); + double frac = j - intgr; + const double gregjd = 2299160.5; + double j1; + if (j >= gregjd) + { + double tmp = Math.Floor(d: (intgr - 1867216.0 - 0.25) / 36524.25); + j1 = intgr + 1 + tmp - Math.Floor(d: 0.25 * tmp); + } + else + { + j1 = intgr; + } + double df = frac + 0.5; + if (df >= 1.0) + { + df--; + ++j1; + } + double j2 = j1 + 1524.0; + double j3 = Math.Floor(d: 6680.0 + ((j2 - 2439870.0 - 122.1) / 365.25)); + double j4 = Math.Floor(d: j3 * 365.25); + double j5 = Math.Floor(d: (j2 - j4) / 30.6001); + double d = Math.Floor(d: j2 - j4 - Math.Floor(d: j5 * 30.6001)); + double m = Math.Floor(d: j5 - 1.0); + if (m > 12) + { + m -= 12; + } + double y = Math.Floor(d: j3 - 4715.0); + if (m > 2) + { + --y; + } + if (y <= 0) + { + --y; + } + double d1 = df * 24.0; + double hr = Math.Floor(d: d1); + double mn = Math.Floor(d: ((df * 24.0) - hr) * 60.0); + double f = ((((df * 24.0) - hr) * 60.0) - mn) * 60.0; + double sc = Math.Floor(d: f); + f -= sc; + if (f > 0.5) + { + ++sc; + } + if (sc == 60) + { + sc = 0; + ++mn; + } + if (mn == 60) + { + mn = 0; + ++hr; + } + if (hr == 24) + { + hr = 0; + ++d; + } + /*if (y < 0) { } else { }*/ - return new DateTime(year: (int)y, month: (int)m, day: (int)d, hour: (int)hr, minute: (int)mn, second: (int)sc); - } - - /// - /// Convert the Julian Date to the Modified Julian Date - /// - /// Julian Date - /// Modified Julian Date - public static double ConvertJulianDateToModifiedJulianDate(double julianDate) => julianDate - doubleModifiedJulianDateCoefficient; - - /// - /// Convert the Modified Julian Date to the Julian Date - /// - /// Modified Julian Date - /// Julian Date - public static double ConvertModifiedJulianDateToJulianDate(double julianModifiedDate) => julianModifiedDate + doubleModifiedJulianDateCoefficient; - - /// - /// Convert the Julian Date to the Reduced Julian Date - /// - /// Julian Date - /// Reduced Julian Date - public static double ConvertJulianDateToReducedJulianDate(double julianDate) => julianDate - doubleReducedJulianDateCoefficient; - - /// - /// Convert the Julian Date to the Truncated Julian Date - /// - /// Julian Date - /// Truncated Julian Date - public static double ConvertJulianDateToTruncatedJulianDate(double julianDate) => julianDate - doubleTruncatedJulianDateCoefficient; - - /// - /// Convert the Julian Date to the Dublin Julian Date - /// - /// Julian Date - /// Dublin Julian Date - public static double ConvertJulianDateToDublinJulianDate(double julianDate) => julianDate - doubleDublinJulianDateCoefficient; - - /// - /// Convert the Julian Date the CNES Julian Date - /// - /// Julian Date - /// CNES Julian Date - public static double ConvertJulianDateToCnesJulianDate(double julianDate) => julianDate - doubleCnesJulianDateCoefficient; - - /// - /// Convert the Julian Date to the CCSDS Julian Date - /// - /// Julian Date - /// CCSDS Julian Date - public static double ConvertJulianDateToCcsdsJulianDate(double julianDate) => julianDate - doubleCcsdsJulianDateCoefficient; - - /// - /// Convert the Julian Date to the LOP Julian Date - /// - /// Julian Date - /// LOP Julian Date - public static double ConvertJulianDateToLopJulianDate(double julianDate) => julianDate - doubleLopJulianDateCoefficient; - - /// - /// Convert the Julian Date to the Millenium Julian Date - /// - /// Julian Date - /// - public static double ConvertJulianDateToMillenniumJulianDate(double julianDate) => julianDate - doubleMillenniumJulianDateCoefficient; - - /// - /// Convert the Julian Date to the Chronological Julian Date - /// - /// Julian Date - /// Chronological Julian Date - public static double ConvertJulianDateToChronologicalJulianDate(double julianDate) => CalculateChronologicalJulianDate(julianDate: julianDate); - - /// - /// Convert the Julian Date to the Chronological Modified Julian Date - /// - /// Julian Date - /// Chronological Modified Julian Date - public static double ConvertJulianDateToChronologicalModifiedJulianDate(double julianDate) => CalculateChronologicalModifiedJulianDate(julianDate: julianDate); - - /// - /// Convert the Julian Date to the Lilian Date - /// - /// Julian Date - /// Lilian Date - public static double ConvertJulianDateToLilianDate(double julianDate) => julianDate - doubleLilianDateCoefficient; - - /// - /// Convert the Julian Date to the Rata Die - /// - /// Julian Date - /// Rata Die - public static double ConvertJulianDateToRataDie(double julianDate) => julianDate - doubleRataDieCoefficient; - - /// - /// Convert the Julian Date to the Mars Sol Date - /// - /// Julian Date - /// Mars Sol Date - public static double ConvertJulianDateToMarsSolDate(double julianDate) => julianDate - doubleMarsSolDateCoefficient; - - /// - /// Convert the Julian Date to the Unix Time - /// - /// Julian Date - /// Unix Time - public static double ConvertJulianDateToUnixtime(double julianDate) => julianDate - doubleUnixtimeCoefficient; - - #endregion - } + return new DateTime( + year: (int)y, + month: (int)m, + day: (int)d, + hour: (int)hr, + minute: (int)mn, + second: (int)sc); + } + + /// + /// Convert the Julian Date to the Modified Julian Date + /// + /// Julian Date + /// Modified Julian Date + public static double ConvertJulianDateToModifiedJulianDate(double julianDate) => julianDate - + doubleModifiedJulianDateCoefficient; + + /// + /// Convert the Modified Julian Date to the Julian Date + /// + /// Modified Julian Date + /// Julian Date + public static double ConvertModifiedJulianDateToJulianDate(double julianModifiedDate) => julianModifiedDate + + doubleModifiedJulianDateCoefficient; + + /// + /// Convert the Julian Date to the Reduced Julian Date + /// + /// Julian Date + /// Reduced Julian Date + public static double ConvertJulianDateToReducedJulianDate(double julianDate) => julianDate - + doubleReducedJulianDateCoefficient; + + /// + /// Convert the Julian Date to the Truncated Julian Date + /// + /// Julian Date + /// Truncated Julian Date + public static double ConvertJulianDateToTruncatedJulianDate(double julianDate) => julianDate - + doubleTruncatedJulianDateCoefficient; + + /// + /// Convert the Julian Date to the Dublin Julian Date + /// + /// Julian Date + /// Dublin Julian Date + public static double ConvertJulianDateToDublinJulianDate(double julianDate) => julianDate - + doubleDublinJulianDateCoefficient; + + /// + /// Convert the Julian Date the CNES Julian Date + /// + /// Julian Date + /// CNES Julian Date + public static double ConvertJulianDateToCnesJulianDate(double julianDate) => julianDate - + doubleCnesJulianDateCoefficient; + + /// + /// Convert the Julian Date to the CCSDS Julian Date + /// + /// Julian Date + /// CCSDS Julian Date + public static double ConvertJulianDateToCcsdsJulianDate(double julianDate) => julianDate - + doubleCcsdsJulianDateCoefficient; + + /// + /// Convert the Julian Date to the LOP Julian Date + /// + /// Julian Date + /// LOP Julian Date + public static double ConvertJulianDateToLopJulianDate(double julianDate) => julianDate - + doubleLopJulianDateCoefficient; + + /// + /// Convert the Julian Date to the Millenium Julian Date + /// + /// Julian Date + /// + public static double ConvertJulianDateToMillenniumJulianDate(double julianDate) => julianDate - + doubleMillenniumJulianDateCoefficient; + + /// + /// Convert the Julian Date to the Chronological Julian Date + /// + /// Julian Date + /// Chronological Julian Date + public static double ConvertJulianDateToChronologicalJulianDate(double julianDate) => CalculateChronologicalJulianDate( + julianDate: julianDate); + + /// + /// Convert the Julian Date to the Chronological Modified Julian Date + /// + /// Julian Date + /// Chronological Modified Julian Date + public static double ConvertJulianDateToChronologicalModifiedJulianDate(double julianDate) => CalculateChronologicalModifiedJulianDate( + julianDate: julianDate); + + /// + /// Convert the Julian Date to the Lilian Date + /// + /// Julian Date + /// Lilian Date + public static double ConvertJulianDateToLilianDate(double julianDate) => julianDate - + doubleLilianDateCoefficient; + + /// + /// Convert the Julian Date to the Rata Die + /// + /// Julian Date + /// Rata Die + public static double ConvertJulianDateToRataDie(double julianDate) => julianDate - doubleRataDieCoefficient; + + /// + /// Convert the Julian Date to the Mars Sol Date + /// + /// Julian Date + /// Mars Sol Date + public static double ConvertJulianDateToMarsSolDate(double julianDate) => julianDate - + doubleMarsSolDateCoefficient; + + /// + /// Convert the Julian Date to the Unix Time + /// + /// Julian Date + /// Unix Time + public static double ConvertJulianDateToUnixtime(double julianDate) => julianDate - doubleUnixtimeCoefficient; + #endregion + } } \ No newline at end of file