Skip to content

Colossal.Atmosphere.JulianDateTime

Assembly: Assembly-CSharp (in-game)

Namespace: Colossal.Atmosphere

Type: struct

Base: System.ValueType

Summary: Represents a Julian date split into an integer day (m_Day) and a fractional day portion (m_Fraction). Provides conversions to/from System.DateTime (UTC), conversions to double (continuous Julian day), basic arithmetic (adding seconds, subtraction), and helpers to compute Greenwich Mean Sidereal Time (GMST) and Local Mean Sidereal Time (LMST). Intended for astronomical/time calculations used by the atmosphere system (e.g., sun/moon positioning) in Cities: Skylines 2 modding.


Fields

  • private static readonly JulianDateTime J2000 = new JulianDateTime(2451545.0) Represents the Julian date for J2000.0 (2451545.0) used as a reference epoch in some sidereal time calculations.

  • private const double kSecPerDay = 86400.0 Number of seconds in one day. Used when converting seconds to fractional days.

  • private const double kOmegaE = 1.00273790934 A constant related to Earth rotation rate (present in the file but not used in all methods); useful for converting between solar and sidereal time in some contexts.

  • private long m_Day Integer part of the Julian day (stored as a long).

  • private double m_Fraction Fractional part of the Julian day in range [0,1). Represents time of day as a fraction of a day.

Properties

  • This struct does not declare any C# auto-properties. It exposes implicit conversions (operators) to/from DateTime and double instead.

Constructors

  • public JulianDateTime(double j)
    Constructs from a double representing the full Julian day (integer + fraction). Splits into m_Day and m_Fraction.

  • public JulianDateTime(JulianDateTime j)
    Copy constructor. Copies m_Day and m_Fraction from another JulianDateTime.

  • public JulianDateTime(DateTime utc)
    Constructs from a System.DateTime assumed to be UTC (DateTimeKind not enforced). Computes the corresponding Julian day number and fractional day using the standard integer algorithm for Gregorian calendar dates.

Methods

  • public static implicit operator JulianDateTime(DateTime utc)
    Implicit conversion from DateTime to JulianDateTime. Calls the DateTime constructor.

  • public static implicit operator double(JulianDateTime aDate)
    Implicit conversion to double. Returns continuous Julian day (m_Day + m_Fraction).

  • public static implicit operator DateTime(JulianDateTime aDate)
    Implicit conversion to System.DateTime (UTC). Calls ToDateTime().

  • public double ToDouble()
    Returns the Julian date as a double: m_Day + m_Fraction.

  • public DateTime ToDateTime()
    Converts the stored Julian day to a System.DateTime (UTC). Converts the integer/fraction form back into year/month/day and adds the fractional day as hours/minutes/seconds.

  • public override string ToString()
    Returns a human-readable string. If the stored value is NaN, returns "N/A". Otherwise converts to local time and formats as "dd/MM/yyyy HH:mm:ss".

  • public double ToGMST()
    Computes an angle (radians) for Greenwich Mean Sidereal Time using the stored Julian date and a polynomial approximation referenced to J2000.0. The method:

  • normalizes day fraction,
  • computes a centuries-since-epoch term,
  • evaluates a polynomial to get GMST in seconds-of-time,
  • reduces to [0,86400) and converts to radians (2*pi * fraction-of-day). Note: this is an approximate implementation; verify against precise astronomical references if high accuracy is required.

  • public double ToLMST(double longitude)
    Computes Local Mean Sidereal Time by adding the supplied longitude to GMST and reducing to a 2π range. Implementation detail: current code computes ((GMST + longitude) % π) * 2.0 which is mathematically different from (GMST + longitude) % (2π). Be aware this may not produce the expected mapping in all cases — review if you need exact LMST results.

  • public void AddSeconds(double seconds)
    Adds seconds to the current JulianDateTime by converting seconds to fractional days. Normalizes m_Fraction into [0,1) and updates m_Day accordingly.

  • public double Subtract(JulianDateTime j)
    Subtracts another JulianDateTime from this instance (modifies this instance): subtracts day and fraction parts, normalizes the fraction, and returns the resulting Julian date as a double. Note: this method mutates the current instance (reads like subtract-and-assign) and returns the resulting ToDouble().

  • public double Subtract(double j)
    Returns the difference between this JulianDateTime (as double) and a double Julian day j. Does not mutate the instance.

  • public static double operator -(JulianDateTime l, double r)
    Operator overload that returns l - r by delegating to the Subtract(double) behavior (new copy used to avoid mutating original).

  • public static double operator -(JulianDateTime l, JulianDateTime j)
    Operator overload that returns the difference between two JulianDateTime values (in days) by delegating to Subtract(JulianDateTime). Note that Subtract(JulianDateTime) in the implementation mutates the left-hand operand on the copy used by the operator overload (so the operator itself does not mutate the original because it creates a new JulianDateTime(l) internally).

Usage Example

// Create from a UTC DateTime
DateTime utcNow = DateTime.UtcNow;
JulianDateTime jd = utcNow; // implicit conversion

// Convert back to DateTime (UTC)
DateTime backToUtc = (DateTime)jd;

// Add 90 seconds
jd.AddSeconds(90);

// Get Julian day as double
double julianDouble = jd.ToDouble();

// Get GMST (radians)
double gmst = jd.ToGMST();

// Compute LMST for a given longitude (in radians)
double longitudeRadians = 30.0 * Math.PI / 180.0; // example: 30°E
double lmst = jd.ToLMST(longitudeRadians);

// Print readable form
Console.WriteLine(jd.ToString());

Notes and caveats: - The struct stores date/time as a (day, fraction) pair. When adding/subtracting time, the fraction is normalized and days are adjusted. - Some calculations (ToGMST, ToLMST) use approximate polynomial formulas and/or non-standard modulus logic; verify against authoritative astronomical formulas if precise sidereal times are required for your mod. - Subtract(JulianDateTime) is implemented as a mutating subtraction; the operator overloads create a copy before calling it to avoid mutating the original value.