CelestialCalendar 1.0.0 · unreleased development @ 67a7c4c79a4a4a6aa7e703c9e6f0039ae34bee82
Loading...
Searching...
No Matches
calendar Namespace Reference

Namespaces

namespace  detail
namespace  jieqi
namespace  lunar

Classes

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

Concepts

concept  IsDuration
 Checks if a type is of std::chrono::duration.
concept  Fractionable
 Checks if a type can cast to std::chrono::nanoseconds, which is the assumption of function fraction.

Typedefs

using days
using seconds
using nanoseconds
using microseconds
using system_clock
using year_month_day
using sys_days

Functions

template<IsDuration Duration>
consteval auto in_a_day () -> uint64_t
 Returns the number of the given duration in a day.
template<Fractionable Duration>
constexpr auto to_fraction (const Duration &elapsed) -> double
 Returns the fraction of a day.
constexpr auto from_fraction (const double fraction) -> hh_mm_ss< nanoseconds >
 Returns the nanoseconds of fraction days.
constexpr auto validate_fraction (const double fraction) -> double
 Validate the fraction of a day, before any narrowing conversion happens.
constexpr auto add_seconds (const Datetime &dt, const double offset_sec) -> Datetime
 Returns dt shifted by offset_sec seconds, carrying whole days into the date part.

Typedef Documentation

◆ days

◆ microseconds

◆ nanoseconds

◆ seconds

◆ sys_days

◆ system_clock

◆ year_month_day

Function Documentation

◆ add_seconds()

auto calendar::add_seconds ( const Datetime & dt,
const double offset_sec )->Datetime
nodiscardconstexpr

Returns dt shifted by offset_sec seconds, carrying whole days into the date part.

Parameters
dtThe datetime to shift.
offset_secThe offset in seconds. Can be negative, and is not limited to one day.
Returns
The shifted datetime.
Exceptions
std::invalid_argumentif offset_sec is not finite, or if the shifted date leaves std::chrono::year_month_day's representable years.

◆ from_fraction()

auto calendar::from_fraction ( const double fraction) ->hh_mm_ss< nanoseconds >
nodiscardconstexpr

Returns the nanoseconds of fraction days.

Parameters
fractionThe fraction.
Returns
The nanoseconds of fraction days.
Example
from_fraction(0.0) == 00:00:00.000000000
Example
from_fraction(0.5) == 12:00:00.000000000
Example
from_fraction(1.0) == 24:00:00.000000000
Example
from_fraction(2.0) == 48:00:00.000000000
Note
The precision of the returned value is std::chrono::nanoseconds.
Exceptions
std::invalid_argumentif fraction days do not fit an int64_t count of nanoseconds (which includes NaN and either infinity).
Note
Unlike validate_fraction this does not require [0.0, 1.0) — whole days are the documented contract. What it requires is that the product survives the cast, which is undefined outside int64's range; the guard's negated form is validate_fraction's NaN-safe shape (#67, #86).

◆ in_a_day()

template<IsDuration Duration>
auto calendar::in_a_day ( ) ->uint64_t
nodiscardconsteval

Returns the number of the given duration in a day.

Template Parameters
DurationThe duration type.
Returns
The number of the given duration in a day.
Example
in_a_day<days>() == 1
Example
in_a_day<seconds>() == 86400 (There are 86400 seconds in a day.)

◆ to_fraction()

template<Fractionable Duration>
auto calendar::to_fraction ( const Duration & elapsed) ->double
nodiscardconstexpr

Returns the fraction of a day.

Parameters
elapsedThe elapsed time.
Template Parameters
DurationThe type of input elapsed.
Returns
The fraction of a day, of type double.
Note
The type of input elapsed should be convertible to std::chrono::nanoseconds.
Negative and multi-day durations are allowed; the result may be < 0.0 or >= 1.0.
Exceptions
std::invalid_argumentif the nanosecond count is not representable or the input is not finite.

◆ validate_fraction()

auto calendar::validate_fraction ( const double fraction) ->double
nodiscardconstexpr

Validate the fraction of a day, before any narrowing conversion happens.

Parameters
fractionThe fraction of a day, expected in [0.0, 1.0).
Returns
fraction, unchanged.
Exceptions
std::invalid_argumentif fraction is outside [0.0, 1.0).
Note
#67: written as not (x >= lo and x < hi) so NaN fails the check too — a plain fraction < 0.0 or fraction >= 1.0 test is always false for NaN and lets it through to the undefined double→int64 cast in from_fraction.