MT Core (C++)
Core library for replacing C++ standard in project usage
Loading...
Searching...
No Matches
mtcore::calendars::Moment Struct Reference

Base calendar system tracking the number of days (and fraction of days) since its epoch. More...

#include <fixed.hpp>

Public Member Functions

constexpr bool is_valid () const
 Checks that a moment is valid.
 
constexpr Moment to_moment () const
 Time Calendar System contract.
 
constexpr auto operator<=> (const Moment &o) const
 Time Calendar System contract.
 
constexpr Moment add_days (const i32 days) const
 Adds n days to a moment.
 
constexpr Moment sub_days (const i32 days) const
 Subtracts n days from a moment.
 
constexpr i32 day_difference (const Moment &other) const
 Get the difference in days between two moments.
 

Static Public Member Functions

static constexpr Moment from_moment (Moment m)
 Time Calendar System contract.
 
static constexpr Fixed moment_to_fixed (const Moment &m)
 Converts a moment to fixed date (drops time)
 
static constexpr Moment reconstruct (const Fixed &f, const Moment &m)
 Reconstructs a moment from a fixed date and the time portion of a moment.
 

Public Attributes

f64 dayAndTime
 

Static Public Attributes

static constexpr auto EPOCH = FIXED_EPOCH
 
static constexpr std::string_view name = "MOMENT"
 

Detailed Description

Base calendar system tracking the number of days (and fraction of days) since its epoch.

Used as common ground for conversions between calendar systems with time.

Definition at line 264 of file fixed.hpp.

Member Function Documentation

◆ add_days()

Moment mtcore::calendars::Moment::add_days ( const i32 days) const
inlinenodiscardconstexpr

Adds n days to a moment.

Definition at line 292 of file fixed.hpp.

292{ return {dayAndTime + days}; }

◆ day_difference()

i32 mtcore::calendars::Moment::day_difference ( const Moment & other) const
inlinenodiscardconstexpr

Get the difference in days between two moments.

Definition at line 298 of file fixed.hpp.

298 {
299 return math::floor<f64, i32>(dayAndTime - other.dayAndTime);
300 }
constexpr R floor(T num) noexcept
Floors a number with support for constexpr and fast runtime compilation.
Here is the call graph for this function:

◆ from_moment()

static constexpr Moment mtcore::calendars::Moment::from_moment ( Moment m)
inlinestaticnodiscardconstexpr

Time Calendar System contract.

Definition at line 275 of file fixed.hpp.

275{ return m; }

◆ is_valid()

bool mtcore::calendars::Moment::is_valid ( ) const
inlinenodiscardconstexpr

Checks that a moment is valid.

Definition at line 270 of file fixed.hpp.

270{ return std::isfinite(dayAndTime); }

◆ moment_to_fixed()

static constexpr Fixed mtcore::calendars::Moment::moment_to_fixed ( const Moment & m)
inlinestaticnodiscardconstexpr

Converts a moment to fixed date (drops time)

Definition at line 281 of file fixed.hpp.

281 {
282 return {math::floor<f64, i32>(m.dayAndTime)};
283 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ operator<=>()

auto mtcore::calendars::Moment::operator<=> ( const Moment & o) const
inlinenodiscardconstexpr

Time Calendar System contract.

Definition at line 278 of file fixed.hpp.

278{ return dayAndTime <=> o.dayAndTime; }

◆ reconstruct()

static constexpr Moment mtcore::calendars::Moment::reconstruct ( const Fixed & f,
const Moment & m )
inlinestaticnodiscardconstexpr

Reconstructs a moment from a fixed date and the time portion of a moment.

Definition at line 286 of file fixed.hpp.

286 {
287 const auto mt = m.dayAndTime - math::floor<f64, i32>(m.dayAndTime);
288 return {static_cast<f64>(f.day) + mt};
289 }
double f64
Alias for 64-bit floats.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ sub_days()

Moment mtcore::calendars::Moment::sub_days ( const i32 days) const
inlinenodiscardconstexpr

Subtracts n days from a moment.

Definition at line 295 of file fixed.hpp.

295{ return {dayAndTime - days}; }

◆ to_moment()

Moment mtcore::calendars::Moment::to_moment ( ) const
inlinenodiscardconstexpr

Time Calendar System contract.

Definition at line 273 of file fixed.hpp.

273{ return *this; }

Member Data Documentation

◆ dayAndTime

f64 mtcore::calendars::Moment::dayAndTime

Definition at line 267 of file fixed.hpp.

◆ EPOCH

auto mtcore::calendars::Moment::EPOCH = FIXED_EPOCH
staticconstexpr

Definition at line 265 of file fixed.hpp.

◆ name

std::string_view mtcore::calendars::Moment::name = "MOMENT"
staticconstexpr

Definition at line 266 of file fixed.hpp.


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