tempoch-cpp
Header-only C++ wrapper for tempoch
Loading...
Searching...
No Matches
period.hpp
Go to the documentation of this file.
1#pragma once
2
10#include "time.hpp"
11#include <vector>
12
13namespace tempoch {
14
15// ============================================================================
16// Period
17// ============================================================================
18
33class Period {
34 tempoch_period_mjd_t m_inner;
35
36public:
43 Period(double start_mjd, double end_mjd) {
45 tempoch_period_mjd_new(start_mjd, end_mjd, &m_inner),
46 "Period::Period"
47 );
48 }
49
55 Period(const MJD& start, const MJD& end)
56 : Period(start.value(), end.value()) {}
57
59 static Period from_c(const tempoch_period_mjd_t& c) {
60 Period p(0.0, 1.0); // dummy
61 p.m_inner = c;
62 return p;
63 }
64
66 double start_mjd() const { return m_inner.start_mjd; }
67
69 double end_mjd() const { return m_inner.end_mjd; }
70
72 MJD start() const { return MJD(m_inner.start_mjd); }
73
75 MJD end() const { return MJD(m_inner.end_mjd); }
76
78 double duration_days() const {
79 return tempoch_period_mjd_duration_days(m_inner);
80 }
81
88 Period intersection(const Period& other) const {
89 tempoch_period_mjd_t out;
91 tempoch_period_mjd_intersection(m_inner, other.m_inner, &out),
92 "Period::intersection"
93 );
94 return from_c(out);
95 }
96
98 const tempoch_period_mjd_t& c_inner() const { return m_inner; }
99};
100
101} // namespace tempoch
Modified Julian Date wrapper (value type).
Definition time.hpp:158
A time period [start, end] in MJD.
Definition period.hpp:33
double start_mjd() const
Inclusive period start as raw MJD days.
Definition period.hpp:66
Period intersection(const Period &other) const
Compute the overlapping interval with another period.
Definition period.hpp:88
static Period from_c(const tempoch_period_mjd_t &c)
Construct from the C struct (unchecked).
Definition period.hpp:59
MJD start() const
Inclusive period start as a typed MJD value.
Definition period.hpp:72
double duration_days() const
Duration in days.
Definition period.hpp:78
Period(const MJD &start, const MJD &end)
Construct a period from typed MJD values.
Definition period.hpp:55
MJD end() const
Inclusive period end as a typed MJD value.
Definition period.hpp:75
const tempoch_period_mjd_t & c_inner() const
Access the underlying FFI POD value.
Definition period.hpp:98
Period(double start_mjd, double end_mjd)
Construct a period from start/end MJD values.
Definition period.hpp:43
double end_mjd() const
Inclusive period end as raw MJD days.
Definition period.hpp:69
void check_status(tempoch_status_t status, const char *operation)
Check a tempoch_status_t and throw the appropriate exception on error.
Definition ffi_core.hpp:71
C++ wrappers for Julian Date, Modified Julian Date, and UTC.