Skip to content

Commit

Permalink
fyears
Browse files Browse the repository at this point in the history
  • Loading branch information
xanthos committed Nov 15, 2023
1 parent dece58e commit 02c0275
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
9 changes: 7 additions & 2 deletions src/dtcalendar.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down Expand Up @@ -211,10 +211,15 @@ class datetime_interval {
/* difference in fractional seconds */
const double big = static_cast<double>(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<double>(m_days);
return m_sign * (big + to_fractional_days(S(m_secs)));
} else {
/* difference in fractional years */
const double big = static_cast<double>(m_days);
return m_sign * (big + to_fractional_days(S(m_secs))) /
DAYS_IN_JULIAN_YEAR;
}
}

Expand Down
6 changes: 5 additions & 1 deletion src/tpdate.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<DateTimeDifferenceType::FractionalDays>(d) /
DAYS_IN_JULIAN_YEAR;
}
}

Expand Down

0 comments on commit 02c0275

Please sign in to comment.