21template <
typename S>
class Time;
22template <
typename S,
typename F>
class EncodedTime;
40 "tempoch_context_create_with_builtin_eop");
44inline std::shared_ptr<tempoch_context_t>
48 "tempoch_context_allow_pre_definition_utc");
58template <
typename From,
typename To>
63 "tempoch_time_scale_convert");
67template <
typename S,
typename F>
72 "tempoch_time_to_format");
76template <
typename S,
typename F>
81 "tempoch_time_from_format");
107 return qtty::Second(
out);
115 if (!std::isfinite(raw))
125 std::shared_ptr<tempoch_context_t> handle_;
144template <
typename S>
class Time {
145 static_assert(
is_scale_v<S>,
"Time<S> requires a valid tempoch::scale tag");
151 template <
typename>
friend class Time;
157 Time() : raw_(detail::make_time(0.0, 0.0)) {}
167 return Time(detail::decode_time<S, Fmt>(
encoded.value(),
nullptr));
171 template <
typename Fmt>
173 return Time(detail::decode_time<S, Fmt>(
encoded.value(),
ctx.get()));
177 return {qtty::Second(raw_.hi_seconds), qtty::Second(raw_.lo_seconds)};
181 return qtty::Second(raw_.hi_seconds + raw_.lo_seconds);
188 template <
typename U = S, std::enable_if_t<std::is_same_v<U, scale::UTC>,
int> = 0>
193 template <
typename U = S, std::enable_if_t<std::is_same_v<U, scale::UTC>,
int> = 0>
198 template <
typename U = S, std::enable_if_t<std::is_same_v<U, scale::UTC>,
int> = 0>
203 template <
typename U = S, std::enable_if_t<std::is_same_v<U, scale::UTC>,
int> = 0>
209 std::enable_if_t<is_scale_v<TargetScale> && !std::is_same_v<S, scale::UT1> &&
210 !std::is_same_v<TargetScale, scale::UT1>,
217 std::enable_if_t<is_scale_v<TargetScale> && (std::is_same_v<S, scale::UT1> ||
218 std::is_same_v<TargetScale, scale::UT1>),
222 template <
typename TargetScale, std::enable_if_t<is_scale_v<TargetScale>,
int> = 0>
239 template <
typename TargetFormat, std::enable_if_t<is_format_v<TargetFormat>,
int> = 0>
242 detail::encode_time<S, TargetFormat>(raw_,
nullptr)));
245 template <
typename TargetFormat, std::enable_if_t<is_format_v<TargetFormat>,
int> = 0>
248 detail::encode_time<S, TargetFormat>(raw_,
ctx.get())));
251 template <
typename TargetScale, std::enable_if_t<is_scale_v<TargetScale>,
int> = 0>
252 std::optional<Time<TargetScale>>
try_to()
const {
255 }
catch (
const std::exception &) {
260 template <
typename TargetFormat, std::enable_if_t<is_format_v<TargetFormat>,
int> = 0>
261 std::optional<EncodedTime<S, TargetFormat>>
try_to()
const {
264 }
catch (
const std::exception &) {
290 return raw_.hi_seconds ==
other.raw_.hi_seconds && raw_.lo_seconds ==
other.raw_.lo_seconds;
296 return raw_.hi_seconds <
other.raw_.hi_seconds ||
297 (raw_.hi_seconds ==
other.raw_.hi_seconds && raw_.lo_seconds <
other.raw_.lo_seconds);
313 static_assert(
is_scale_v<S>,
"EncodedTime<S, F> requires a valid tempoch::scale tag");
314 static_assert(
is_format_v<F>,
"EncodedTime<S, F> requires a valid tempoch::format tag");
328 detail::ensure_finite_encoded<F>(raw_.value(),
"EncodedTime::EncodedTime");
334 if (!std::isfinite(
raw.value()))
348 template <
typename U = F, std::enable_if_t<std::is_same_v<U, format::JD>,
int> = 0>
353 template <
typename TargetScale, std::enable_if_t<is_scale_v<TargetScale>,
int> = 0>
364 template <
typename TargetScale, std::enable_if_t<is_scale_v<TargetScale>,
int> = 0>
375 template <
typename TargetFormat, std::enable_if_t<is_format_v<TargetFormat>,
int> = 0>
380 template <
typename TargetFormat, std::enable_if_t<is_format_v<TargetFormat>,
int> = 0>
385 template <
typename TargetScale, std::enable_if_t<is_scale_v<TargetScale>,
int> = 0>
386 std::optional<Time<TargetScale>>
try_to()
const {
389 }
catch (
const std::exception &) {
394 template <
typename TargetFormat, std::enable_if_t<is_format_v<TargetFormat>,
int> = 0>
395 std::optional<EncodedTime<S, TargetFormat>>
try_to()
const {
398 }
catch (
const std::exception &) {
412 *
this = *
this +
delta;
417 *
this = *
this -
delta;
444 template <
typename U = F, std::enable_if_t<std::is_same_v<U, format::JD>,
int> = 0>
449 template <
typename U = F, std::enable_if_t<std::is_same_v<U, format::MJD>,
int> = 0>
454 template <
typename U = F, std::enable_if_t<std::is_same_v<U, format::JD>,
int> = 0>
456 return qtty::JulianCentury((raw_.value() - 2451545.0) / 36525.0);
459 template <
typename U = F, std::enable_if_t<std::is_same_v<U, format::JD>,
int> = 0>
464 template <
typename U = F, std::enable_if_t<std::is_same_v<U, format::JD>,
int> = 0>
469 template <
typename U = F, std::enable_if_t<std::is_same_v<U, format::MJD>,
int> = 0>
474 template <
typename U = F, std::enable_if_t<std::is_same_v<U, format::JD>,
int> = 0>
479 template <
typename U = F, std::enable_if_t<std::is_same_v<U, format::MJD>,
int> = 0>
484 template <
typename U = S, std::enable_if_t<std::is_same_v<U, scale::TT>,
int> = 0>
489 template <
typename U = S, std::enable_if_t<std::is_same_v<U, scale::TT>,
int> = 0>
494 template <
typename U = S, std::enable_if_t<std::is_same_v<U, scale::TT>,
int> = 0>
499 template <
typename U = S, std::enable_if_t<std::is_same_v<U, scale::TT>,
int> = 0>
505template <
typename S,
typename F>
UTC date-time breakdown struct.
A generic scale/format conversion failed.
A typed external encoding of a time instant on scale S.
bool operator>=(const EncodedTime &other) const noexcept
static EncodedTime from_mjd(const EncodedTime< S, format::MJD > &mjd)
bool operator<(const EncodedTime &other) const noexcept
EncodedTime operator-(const Q &delta) const
quantity_type quantity() const noexcept
EncodedTime mean(const EncodedTime &other) const
EncodedTime< S, TargetFormat > to_with(const TimeContext &ctx) const
bool operator<=(const EncodedTime &other) const noexcept
static std::optional< EncodedTime > try_new(quantity_type raw)
EncodedTime< TargetScale, TargetFormat > to_with(const TimeContext &ctx) const
double julian_centuries() const noexcept
EncodedTime< S, format::JD > to_jd() const
EncodedTime(double value)
static EncodedTime J2000()
bool operator!=(const EncodedTime &other) const noexcept
EncodedTime(quantity_type raw)
EncodedTime< TargetScale, TargetFormat > to() const
static EncodedTime from_utc(const CivilTime &civil)
static EncodedTime from_jd(const EncodedTime< S, format::JD > &jd)
quantity_type raw() const noexcept
static EncodedTime from_raw(quantity_type raw)
EncodedTime min(const EncodedTime &other) const noexcept
typename FormatTraits< F >::quantity_type quantity_type
Time< TargetScale > to_with(const TimeContext &ctx) const
EncodedTime< S, TargetFormat > to() const
double value() const noexcept
EncodedTime & operator-=(const Q &delta)
qtty::JulianCentury julian_centuries_qty() const noexcept
double jd_value() const noexcept
EncodedTime operator+(const Q &delta) const
bool operator>(const EncodedTime &other) const noexcept
CivilTime to_utc(const TimeContext &ctx) const
std::optional< EncodedTime< S, TargetFormat > > try_to() const
EncodedTime & operator+=(const Q &delta)
std::optional< Time< TargetScale > > try_to() const
static EncodedTime from_utc(const CivilTime &civil, const TimeContext &ctx)
EncodedTime< S, format::MJD > to_mjd() const
quantity_type operator-(const EncodedTime &other) const
bool operator==(const EncodedTime &other) const noexcept
EncodedTime max(const EncodedTime &other) const noexcept
double mjd_value() const noexcept
Immutable conversion context for UT1 and historical UTC routes.
const tempoch_context_t * get() const noexcept
TimeContext allow_pre_definition_utc() const
static TimeContext with_builtin_eop()
A point in time on scale S, stored as a split J2000-second pair.
static Time from_civil(const CivilTime &civil)
Time operator-(const Q &delta) const
EncodedTime< S, TargetFormat > to_with(const TimeContext &ctx) const
std::optional< EncodedTime< S, TargetFormat > > try_to() const
static constexpr const char * label()
Time< TargetScale > to() const =delete
EncodedTime< TargetScale, TargetFormat > to_with(const TimeContext &ctx) const
std::pair< qtty::Second, qtty::Second > split_seconds() const noexcept
bool operator==(const Time &other) const noexcept
CivilTime to_civil(const TimeContext &ctx) const
bool operator<=(const Time &other) const noexcept
const tempoch_time_t & c_inner() const noexcept
EncodedTime< S, TargetFormat > to() const
static Time from_encoded_with(const EncodedTime< S, Fmt > &encoded, const TimeContext &ctx)
Decode using explicit UTC / UT1 policy from ctx when required by format Fmt.
Time & operator-=(const Q &delta)
bool operator!=(const Time &other) const noexcept
std::optional< Time< TargetScale > > try_to() const
bool operator>=(const Time &other) const noexcept
static Time from_raw_j2000_seconds(qtty::Second seconds)
static Time from_civil(const CivilTime &civil, const TimeContext &ctx)
Time< TargetScale > to() const
static Time from_split_seconds(qtty::Second hi, qtty::Second lo=qtty::Second(0.0))
Time< TargetScale > to_with(const TimeContext &ctx) const
qtty::Second total_seconds() const noexcept
Time & operator+=(const Q &delta)
Time operator+(const Q &delta) const
EncodedTime< TargetScale, TargetFormat > to() const
qtty::Second operator-(const Time &other) const
static Time from_encoded(const EncodedTime< S, Fmt > &encoded)
Decode a scalar encoding Fmt into canonical split storage on scale S (default context).
bool operator<(const Time &other) const noexcept
CivilTime to_civil() const
bool operator>(const Time &other) const noexcept
Error handling for the tempoch C++ wrapper.
qtty::Second difference_seconds(const tempoch_time_t &lhs, const tempoch_time_t &rhs)
void ensure_finite_encoded(double raw, const char *operation)
double encode_time(const tempoch_time_t &value, const tempoch_context_t *ctx)
tempoch_time_t decode_time(double raw, const tempoch_context_t *ctx)
std::shared_ptr< tempoch_context_t > make_builtin_eop_context()
CivilTime time_to_civil(const tempoch_time_t &value, const tempoch_context_t *ctx)
std::shared_ptr< tempoch_context_t > make_default_context()
FormatTraits< F >::quantity_type quantity_from_raw(double raw)
tempoch_time_t scale_convert(const tempoch_time_t &value, const tempoch_context_t *ctx)
tempoch_time_t time_from_civil(const CivilTime &civil, const tempoch_context_t *ctx)
tempoch_time_t add_seconds(const tempoch_time_t &value, const Q &qty)
std::shared_ptr< tempoch_context_t > make_pre_definition_context(const tempoch_context_t *parent)
tempoch_time_t make_time(double hi_seconds, double lo_seconds)
std::ostream & operator<<(std::ostream &os, const CivilTime &u)
Stream CivilTime as YYYY-MM-DD HH:MM:SS[.nnnnnnnnn].
void check_status(tempoch_status_t status, const char *operation)
Check a tempoch_status_t and throw the appropriate exception on error.
constexpr tempoch_scale_tag_t scale_tag_v
Time-scale tag types for the tempoch C++ API.
static CivilTime from_c(const tempoch_utc_t &c)
Create from the C FFI struct.
void operator()(tempoch_context_t *ptr) const noexcept