diff --git a/src/dtcalendar.hpp b/src/dtcalendar.hpp index d0b9b21..a93aac1 100644 --- a/src/dtcalendar.hpp +++ b/src/dtcalendar.hpp @@ -87,7 +87,7 @@ int sgn(DType val) noexcept { } /* namespace core*/ -enum class DateTimeDifferenceType { FractionalDays, FractionalSeconds }; +enum class DateTimeDifferenceType { FractionalYears, FractionalDays, FractionalSeconds }; /** @brief A generic, templatized class to hold a datetime period/interval. * @@ -211,10 +211,15 @@ class datetime_interval { /* difference in fractional seconds */ const double big = static_cast(seconds::max_in_day * m_days); return m_sign * (big + to_fractional_seconds(S(m_secs))); - } else { + } else if constexpr (DT == DateTimeDifferenceType::FractionalDays) { /* difference in fractional days */ const double big = static_cast(m_days); return m_sign * (big + to_fractional_days(S(m_secs))); + } else { + /* difference in fractional years */ + const double big = static_cast(m_days); + return m_sign * (big + to_fractional_days(S(m_secs))) / + DAYS_IN_JULIAN_YEAR; } } diff --git a/src/tpdate.hpp b/src/tpdate.hpp index 2d8947b..12d1a13 100644 --- a/src/tpdate.hpp +++ b/src/tpdate.hpp @@ -379,9 +379,13 @@ class TwoPartDate { if constexpr (DT == DateTimeDifferenceType::FractionalDays) { /* difference as fractional days */ return (_mjd - d._mjd) + (_fsec - d._fsec) / SEC_PER_DAY; - } else { + } else if constexpr (DT == DateTimeDifferenceType::FractionalSeconds) { /* difference as fractional seconds */ return (_fsec - d._fsec) + (_mjd - d._mjd) * SEC_PER_DAY; + } else { + /* difference as fractional (julian) years */ + return this->diff(d) / + DAYS_IN_JULIAN_YEAR; } }