CelestialCalendar 1.0.0 · unreleased development @ 67a7c4c79a4a4a6aa7e703c9e6f0039ae34bee82
Loading...
Searching...
No Matches
calendar::Datetime Struct Reference

Represents a date and a time in the form of year_month_day and hh_mm_ss. More...

#include <datetime.hpp>

Public Member Functions

 Datetime ()=delete
template<IsDuration Duration>
constexpr Datetime (const time_point< system_clock, Duration > &tp)
 Constructs a Datetime from a time_point.
template<IsDuration Duration>
constexpr Datetime (const year_month_day &ymd, const Duration elapsed)
 Constructs a Datetime from a date and a raw duration since the start of that day.
constexpr Datetime (const year_month_day &ymd, double fraction)
 Constructs a Datetime from a year_month_day and a fraction of a day.
constexpr auto ok () const noexcept -> bool
 Checks if the underlying gregorian date and time are valid and within the supported range.
constexpr auto year () const noexcept -> int32_t
 Returns the year.
constexpr auto month () const noexcept -> uint32_t
 Returns the month.
constexpr auto day () const noexcept -> uint32_t
 Returns the day.
constexpr auto fraction () const noexcept -> double
 Returns the fraction of a day, in the range [0.0, 1.0).
constexpr auto operator== (const Datetime &other) const noexcept -> bool
constexpr auto operator<=> (const Datetime &other) const noexcept

Public Attributes

year_month_day ymd
hh_mm_ss< nanoseconds > time_of_day

Detailed Description

Represents a date and a time in the form of year_month_day and hh_mm_ss.

Note
The precision of the time_of_day field is std::chrono::nanoseconds.
The time_of_day field (i.e. hh_mm_ss) is positive and less than 24:00:00.0 (i.e. 1 day).
No time zone is assumed.

This struct is used to represent UT1, UTC, and TT time in this project.

Constructor & Destructor Documentation

◆ Datetime() [1/4]

calendar::Datetime::Datetime ( )
delete

◆ Datetime() [2/4]

template<IsDuration Duration>
calendar::Datetime::Datetime ( const time_point< system_clock, Duration > & tp)
inlineexplicitconstexpr

Constructs a Datetime from a time_point.

Parameters
tpThe time point. The expected clock is system_clock.
Exceptions
std::invalid_argumentIf the input is non-finite, outside the Gregorian year range, or cannot be represented during conversion.
Note
Floating-point rounding can make the day remainder unrepresentable near midnight; such inputs are rejected.

◆ Datetime() [3/4]

template<IsDuration Duration>
calendar::Datetime::Datetime ( const year_month_day & ymd,
const Duration elapsed )
inlineexplicitconstexpr

Constructs a Datetime from a date and a raw duration since the start of that day.

Parameters
ymdThe year, month, and day.
elapsedThe finite time of day in [0, 24h), checked before and after conversion to nanoseconds.
Exceptions
std::invalid_argumentIf the date is invalid, the duration is non-finite, or the original or converted duration is outside [0, 24h).

◆ Datetime() [4/4]

calendar::Datetime::Datetime ( const year_month_day & ymd,
double fraction )
inlineexplicitconstexpr

Constructs a Datetime from a year_month_day and a fraction of a day.

Parameters
ymdThe year, month, and day.
fractionThe fraction of a day, in the range [0.0, 1.0).

Member Function Documentation

◆ day()

auto calendar::Datetime::day ( ) const->uint32_t
inlinenodiscardconstexprnoexcept

Returns the day.

◆ fraction()

auto calendar::Datetime::fraction ( ) const->double
inlinenodiscardconstexprnoexcept

Returns the fraction of a day, in the range [0.0, 1.0).

Returns
The fraction of a day, expected to be in the range [0.0, 1.0).

◆ month()

auto calendar::Datetime::month ( ) const->uint32_t
inlinenodiscardconstexprnoexcept

Returns the month.

◆ ok()

auto calendar::Datetime::ok ( ) const->bool
inlinenodiscardconstexprnoexcept

Checks if the underlying gregorian date and time are valid and within the supported range.

Returns
true if all good, false otherwise.

◆ operator<=>()

auto calendar::Datetime::operator<=> ( const Datetime & other) const
inlinenodiscardconstexprnoexcept

◆ operator==()

auto calendar::Datetime::operator== ( const Datetime & other) const->bool
inlinenodiscardconstexprnoexcept

◆ year()

auto calendar::Datetime::year ( ) const->int32_t
inlinenodiscardconstexprnoexcept

Returns the year.

Member Data Documentation

◆ time_of_day

hh_mm_ss<nanoseconds> calendar::Datetime::time_of_day

◆ ymd

year_month_day calendar::Datetime::ymd

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