Skip to content

Colossal.Atmosphere.Internal.JulianDateTime

Assembly:
(assembly not provided in source — likely part of the game's Atmosphere/Colossal assembly)

Namespace: Colossal.Atmosphere.Internal

Type: static class

Base: System.Object

Summary:
Utility class providing conversions between calendar date/time values and Julian Date (astronomical Julian day number with fractional day). It implements detection of whether a given calendar date should be interpreted using the Julian calendar or the Gregorian calendar (the switch in October 1582), a method to convert a calendar date/time to a Julian Date double, and extension helpers to convert System.DateTime to/from Julian Date. Note: the reverse conversion method (JulianDateToDate) is present but currently unimplemented in the provided source.


Fields

  • None.
    This static class has no instance or static fields. All functionality is provided via methods.

Properties

  • None.
    There are no properties defined.

Constructors

  • None (static class).
    As a static class, it cannot be instantiated and has no constructors.

Methods

  • public static bool IsJulianDate(int year, int month, int day)
    Determines whether the provided calendar date should be interpreted under the Julian calendar or the Gregorian calendar. Returns true for Julian calendar dates, false for Gregorian. Behavior details:
  • Dates before year 1582 -> Julian (true).
  • Dates after 1582 -> Gregorian (false).
  • For year 1582:

    • Months before October -> Julian (true).
    • Months after October -> Gregorian (false).
    • For October (month == 10):
    • day < 5 -> Julian (true).
    • day > 14 -> Gregorian (false).
    • days 5 through 14 (inclusive) are invalid because they do not exist in either calendar in the historical switch and the method throws an ArgumentOutOfRangeException in that case:
      • ArgumentOutOfRangeException("This date is not valid as it does not exist in either the Julian or the Gregorian calendars.")
  • private static double DateToJulianDate(int year, int month, int day, int hour, int minute, int second, int millisecond)
    Converts the specified calendar date/time to a Julian Date (double). Implementation notes:

  • Uses the standard algorithm:
    • Adjusts month/year if month <= 2 (month += 12; year -= 1).
    • Computes day fraction using hour, minute, second, millisecond.
    • Applies Gregorian correction term B = 2 - (Y/100) + (Y/100)/4 when the date is Gregorian (as determined via IsJulianDate).
    • Returns JD using floor-like integer casts of 365.25(Y+4716) and 30.6001(M+1), adding day fraction and correction, subtracting 1524.5.
  • The resulting Julian Date is the conventional astronomical Julian Date (with fractional part representing time of day).
  • The method does not validate calendar correctness beyond the IsJulianDate check for the October 1582 gap (it will compute a value for dates like February 30 without throwing).
  • Thread-safe and pure (no side effects).

  • private static DateTime JulianDateToDate(double julianDate)
    Intended to convert a Julian Date back to a System.DateTime. In the provided source this method is unimplemented and returns default(DateTime). Until implemented, ConvertToDateTime will not produce a meaningful DateTime result.

  • public static double ConvertToJulianDateTime(int year, int month, int day, int hour, int minute, int second, int millisecond)
    Public wrapper that forwards to DateToJulianDate. Use to get a Julian Date from explicit date/time components.

  • public static double ConvertToJulianDateTime(this DateTime date)
    Extension method on System.DateTime. Converts the given DateTime to a Julian Date (double) by forwarding its Year, Month, Day, Hour, Minute, Second, Millisecond to DateToJulianDate.

  • public static DateTime ConvertToDateTime(this double date)
    Extension method intended to convert a Julian Date (double) back to a System.DateTime by forwarding to JulianDateToDate. Note: because JulianDateToDate is unimplemented in the provided source, this method currently returns default(DateTime).

Usage Example

// Convert a specific date/time to Julian Date
double jd = Colossal.Atmosphere.Internal.JulianDateTime.ConvertToJulianDateTime(2023, 3, 20, 12, 0, 0, 0);

// Or using the DateTime extension:
DateTime now = DateTime.UtcNow;
double jdNow = now.ConvertToJulianDateTime();

// Attempt to convert back (not implemented in the provided source — will return default(DateTime))
DateTime back = jdNow.ConvertToDateTime();

Notes and caveats: - The class handles the historical Julian-to-Gregorian transition in October 1582 and will throw for dates that fall into the missing gap (5–14 October 1582). - JulianDateToDate is currently a stub and must be implemented to enable round-trip conversions (double -> DateTime). - The conversion algorithm uses the conventional astronomical Julian Date formulation (fractional days included). Be mindful of the time-zone context of the input DateTime — the method uses the DateTime components as provided; if you need UTC-based JD values, pass UTC DateTime values. - The methods are pure and thread-safe.