tempoch-cpp
Header-only C++ wrapper for tempoch
Loading...
Searching...
No Matches
tempoch::Period Class Reference

A time period [start, end] in MJD. More...

#include <tempoch/period.hpp>

Public Member Functions

 Period (double start_mjd, double end_mjd)
 Construct a period from start/end MJD values.
 
 Period (const MJD &start, const MJD &end)
 Construct a period from typed MJD values.
 
double start_mjd () const
 Inclusive period start as raw MJD days.
 
double end_mjd () const
 Inclusive period end as raw MJD days.
 
MJD start () const
 Inclusive period start as a typed MJD value.
 
MJD end () const
 Inclusive period end as a typed MJD value.
 
double duration_days () const
 Duration in days.
 
Period intersection (const Period &other) const
 Compute the overlapping interval with another period.
 
const tempoch_period_mjd_t & c_inner () const
 Access the underlying FFI POD value.
 

Static Public Member Functions

static Period from_c (const tempoch_period_mjd_t &c)
 Construct from the C struct (unchecked).
 

Detailed Description

A time period [start, end] in MJD.

Wraps tempoch_period_mjd_t and provides duration, intersection, and easy access to the start/end as MJD objects.

tempoch::Period night(60200.0, 60200.5);
double hours = night.duration_days() * 24.0;
tempoch::Period obs(60200.2, 60200.8);
auto overlap = night.intersection(obs); // [0.2, 0.5]
A time period [start, end] in MJD.
Definition period.hpp:33
Examples
time_example.cpp.

Definition at line 33 of file period.hpp.

Constructor & Destructor Documentation

◆ Period() [1/2]

tempoch::Period::Period ( double  start_mjd,
double  end_mjd 
)
inline

Construct a period from start/end MJD values.

Parameters
start_mjdInclusive start instant, in MJD days.
end_mjdInclusive end instant, in MJD days.
Exceptions
InvalidPeriodErrorIf start_mjd is greater than end_mjd.

Definition at line 43 of file period.hpp.

References tempoch::check_status(), end_mjd(), and start_mjd().

◆ Period() [2/2]

tempoch::Period::Period ( const MJD start,
const MJD end 
)
inline

Construct a period from typed MJD values.

Parameters
startInclusive start instant.
endInclusive end instant.

Definition at line 55 of file period.hpp.

Member Function Documentation

◆ c_inner()

const tempoch_period_mjd_t & tempoch::Period::c_inner ( ) const
inline

Access the underlying FFI POD value.

Definition at line 98 of file period.hpp.

◆ duration_days()

double tempoch::Period::duration_days ( ) const
inline

Duration in days.

Definition at line 78 of file period.hpp.

◆ end()

MJD tempoch::Period::end ( ) const
inline

Inclusive period end as a typed MJD value.

Definition at line 75 of file period.hpp.

◆ end_mjd()

double tempoch::Period::end_mjd ( ) const
inline

Inclusive period end as raw MJD days.

Examples
time_example.cpp.

Definition at line 69 of file period.hpp.

Referenced by main(), and Period().

◆ from_c()

static Period tempoch::Period::from_c ( const tempoch_period_mjd_t &  c)
inlinestatic

Construct from the C struct (unchecked).

Definition at line 59 of file period.hpp.

Referenced by intersection().

◆ intersection()

Period tempoch::Period::intersection ( const Period other) const
inline

Compute the overlapping interval with another period.

Parameters
otherThe period to intersect with.
Returns
The overlap interval.
Exceptions
NoIntersectionErrorIf the two periods do not overlap.
Examples
time_example.cpp.

Definition at line 88 of file period.hpp.

References tempoch::check_status(), and from_c().

Referenced by main().

◆ start()

MJD tempoch::Period::start ( ) const
inline

Inclusive period start as a typed MJD value.

Definition at line 72 of file period.hpp.

◆ start_mjd()

double tempoch::Period::start_mjd ( ) const
inline

Inclusive period start as raw MJD days.

Examples
time_example.cpp.

Definition at line 66 of file period.hpp.

Referenced by main(), and Period().


The documentation for this class was generated from the following file: