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

#include <time.hpp>

Public Member Functions

constexpr Result< void, TimeValidationErrortry_validate () const
 Tries to validate.
 
constexpr operator DayFraction () const
 
constexpr operator Segments () const
 
constexpr auto operator<=> (const NanoSeconds &o) const
 
bool operator== (const NanoSeconds &o) const
 
bool operator!= (const NanoSeconds &o) const
 
bool operator< (const NanoSeconds &o) const
 
bool operator> (const NanoSeconds &o) const
 
bool operator<= (const NanoSeconds &o) const
 
bool operator>= (const NanoSeconds &o) const
 

Public Attributes

u64 nano
 

Static Public Attributes

static constexpr auto max = NANOS_PER_DAY
 

Detailed Description

Definition at line 149 of file calendars/mtcore_calendars/time.hpp.

Member Function Documentation

◆ operator DayFraction()

mtcore::calendars::NanoSeconds::operator DayFraction ( ) const
explicitnodiscardconstexpr

Definition at line 218 of file calendars/mtcore_calendars/time.hpp.

218 {
219 ensure(try_validate().is_success());
220 const auto nano = static_cast<f80>(this->nano);
221 const auto res = DayFraction{.frac = static_cast<f64>(nano) / static_cast<f64>(NANOS_PER_DAY)};
222 ensure(res.try_validate().is_success());
223 return res;
224 }
constexpr i64 NANOS_PER_DAY
Number of nanoseconds per day.
#define ensure(check,...)
Ensures that a check holds true, aborts the program if not true Will print error if the condition is ...
double f64
Alias for 64-bit floats.
long double f80
Alias for 80-bit floats.
constexpr Result< void, TimeValidationError > try_validate() const
Tries to validate.
Here is the call graph for this function:

◆ operator Segments()

mtcore::calendars::NanoSeconds::operator Segments ( ) const
explicitnodiscardconstexpr

Definition at line 226 of file calendars/mtcore_calendars/time.hpp.

226 {
227 ensure(try_validate().is_success());
228
229 u64 val = this->nano;
230
234
235 const auto seconds = math::mod<u64, u64, u8>(val, 60);
236 ensure(seconds < 60);
237 val /= 60;
238
239 const auto minutes = math::mod<u64, u64, u8>(val, 60);
240 ensure(minutes < 60);
241 val /= 60;
242
243 ensure(val < 24);
244 const auto res = Segments{
245 .hour = static_cast<u8>(val),
246 .minute = minutes,
247 .second = seconds,
248 .nano = nano,
249 };
250
251 ensure(res.try_validate().is_success());
252 return res;
253 }
constexpr i32 NANOS_PER_SECOND
Number of nanoseconds per second.
ValIter< T > val(const T &r)
Generic value iterator that uses the operator[] and incrementing indexes to iterate over a collection...
Definition iter.hpp:114
constexpr Res mod(L left, R right) noexcept
Calculates the mathematical mod of two numbers.
uint64_t u64
Alias for 64-bit unsigned ints.
uint8_t u8
Alias for 8-bit unsigned ints.
Here is the call graph for this function:

◆ operator!=()

bool mtcore::calendars::NanoSeconds::operator!= ( const NanoSeconds & o) const
inlinenodiscard

Definition at line 167 of file calendars/mtcore_calendars/time.hpp.

167{ return (*this <=> o) != std::strong_ordering::equal; }

◆ operator<()

bool mtcore::calendars::NanoSeconds::operator< ( const NanoSeconds & o) const
inlinenodiscard

Definition at line 168 of file calendars/mtcore_calendars/time.hpp.

168{ return (*this <=> o) == std::strong_ordering::less; }

◆ operator<=()

bool mtcore::calendars::NanoSeconds::operator<= ( const NanoSeconds & o) const
inlinenodiscard

Definition at line 170 of file calendars/mtcore_calendars/time.hpp.

170 {
171 const auto cmp = (*this <=> o);
172 return cmp == std::strong_ordering::equal || cmp == std::strong_ordering::less;
173 }

◆ operator<=>()

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

Definition at line 164 of file calendars/mtcore_calendars/time.hpp.

164{ return nano <=> o.nano; }

◆ operator==()

bool mtcore::calendars::NanoSeconds::operator== ( const NanoSeconds & o) const
inlinenodiscard

Definition at line 166 of file calendars/mtcore_calendars/time.hpp.

166{ return (*this <=> o) == std::strong_ordering::equal; }

◆ operator>()

bool mtcore::calendars::NanoSeconds::operator> ( const NanoSeconds & o) const
inlinenodiscard

Definition at line 169 of file calendars/mtcore_calendars/time.hpp.

169{ return (*this <=> o) == std::strong_ordering::greater; }

◆ operator>=()

bool mtcore::calendars::NanoSeconds::operator>= ( const NanoSeconds & o) const
inlinenodiscard

Definition at line 174 of file calendars/mtcore_calendars/time.hpp.

174 {
175 const auto cmp = (*this <=> o);
176 return cmp == std::strong_ordering::equal || cmp == std::strong_ordering::greater;
177 }

◆ try_validate()

Result< void, TimeValidationError > mtcore::calendars::NanoSeconds::try_validate ( ) const
inlinenodiscardconstexpr

Tries to validate.

Will return validation error describing what's wrong if invalid.

Definition at line 154 of file calendars/mtcore_calendars/time.hpp.

154 {
155 if (nano >= max) {
157 }
158 return success();
159 }
Success< void > success()
Creates a successful void Result object.
Definition result.hpp:398
Error< Underlying > error(Underlying err)
Creates an error.
Definition result.hpp:425
Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ max

auto mtcore::calendars::NanoSeconds::max = NANOS_PER_DAY
staticconstexpr

Definition at line 150 of file calendars/mtcore_calendars/time.hpp.

◆ nano

u64 mtcore::calendars::NanoSeconds::nano

Definition at line 151 of file calendars/mtcore_calendars/time.hpp.


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