From c0daaa6f37dd479411702d8492eee812017060bd Mon Sep 17 00:00:00 2001 From: xanthos Date: Fri, 24 Nov 2023 17:03:09 +0200 Subject: [PATCH] added static constructor for tpdate --- src/tpdate.hpp | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/src/tpdate.hpp b/src/tpdate.hpp index 12d1a13..5bdcc52 100644 --- a/src/tpdate.hpp +++ b/src/tpdate.hpp @@ -249,17 +249,41 @@ class TwoPartDate { int _mjd; /** Mjd */ FDOUBLE _fsec; /** fractional seconds of day */ + /* a constexpr constructor that will not check arguments, and will NOT + * normalize the date. Be very carefull with this one! + */ + constexpr explicit TwoPartDate(int mjd, FDOUBLE secday, + [[maybe_unused]] char c) noexcept + : _mjd(mjd), _fsec(secday) {} + public: - /** Constructor from datetime */ + /** Constructor from datetime + * Note that we are not (explicitly) normalizing the instance here, because + * the parameter \p d is already considered to hold a 'normalized' datetime. + * */ #if __cplusplus >= 202002L template #else template > #endif - TwoPartDate(const datetime &d) noexcept + constexpr TwoPartDate(const datetime &d) noexcept : _mjd(d.imjd().as_underlying_type()), _fsec(to_fractional_seconds(d.sec())) { - this->normalize(); + } + + /** Reference epoch (J2000.0), as a Modified Julian Date. */ + static constexpr TwoPartDate j2000_mjd() noexcept { + return TwoPartDate(51544, 86400e0 / 2e0, 'y'); + } + + /** Min date */ + static constexpr TwoPartDate min() noexcept { + return TwoPartDate(datetime::min()); + } + + /** Max date */ + static constexpr TwoPartDate max() noexcept { + return TwoPartDate(datetime::max()); } /** Constructor from a pair of doubles, such that MJD = a + b */