AnCH Framework 0.2
Another C++ Hack: C++23 utility libraries
Loading...
Searching...
No Matches
anch::date::Time Class Reference

Time of day (RFC 3339 partial-time , SQL TIME , XSD xs:time without time zone). More...

#include <time.hpp>

Collaboration diagram for anch::date::Time:

Public Member Functions

constexpr Time () noexcept
 Time (unsigned hour, unsigned minute, unsigned second=0, uint32_t nanosecond=0)
 Time (std::chrono::nanoseconds sinceMidnight)
std::string format () const
constexpr unsigned hour () const noexcept
constexpr unsigned minute () const noexcept
constexpr unsigned second () const noexcept
constexpr uint32_t nanosecond () const noexcept
Time plus (std::chrono::nanoseconds duration) const noexcept
constexpr std::strong_ordering operator<=> (const Time &other) const noexcept
constexpr bool operator== (const Time &other) const noexcept
constexpr operator std::chrono::nanoseconds () const noexcept

Static Public Member Functions

static Time now (anch::date::Zone zone=anch::date::Zone::LOCAL)
static Time parse (std::string_view text)

Detailed Description

Time of day (RFC 3339 partial-time , SQL TIME , XSD xs:time without time zone).

A Time is a time of day with a nanosecond precision, from 00:00:00 to 23:59:59.999999999, without time zone: it is always valid (impossible times are refused when it is built ; leap seconds can not be represented without a day). It is not a point in time ( DateTime ): conversions between them give the time zone ( DateTime::time , Date::at ).

#include "date/time.hpp"
bool
timeExample() {
using namespace std::chrono_literals;
anch::date::Time opening(9, 30); // impossible times are refused
anch::date::Time closing = opening.plus(9h); // 18:30:00 (wraps around midnight)
bool open = opening <= anch::date::Time::now() && anch::date::Time::now() < closing;
std::cout << closing << " " << open << std::endl; // 18:30:00 ...
return closing.format() == "18:30:00" && meeting.time(anch::date::Zone::UTC) == anch::date::Time(14, 0);
}
Author
Vincent Lachenal
Since
0.3

Constructor & Destructor Documentation

◆ Time() [1/3]

anch::date::Time::Time ( )
constexprnoexcept

Time default constructor: midnight (00:00:00)

Here is the call graph for this function:

◆ Time() [2/3]

anch::date::Time::Time ( unsigned hour,
unsigned minute,
unsigned second = 0,
uint32_t nanosecond = 0 )

Time constructor

Parameters
hourthe hour (0 to 23)
minutethe minute (0 to 59)
secondthe second (0 to 59)
nanosecondthe nanoseconds of the second (0 to 999999999)
Exceptions
std::invalid_argumentimpossible time
Here is the call graph for this function:

◆ Time() [3/3]

anch::date::Time::Time ( std::chrono::nanoseconds sinceMidnight)
explicit

Time constructor

Parameters
sinceMidnightthe duration since midnight (less than 24 hours)
Exceptions
std::invalid_argumentnegative duration or duration of 24 hours or more

Member Function Documentation

◆ format()

std::string anch::date::Time::format ( ) const

Format RFC 3339 partial-time (fraction written with the number of digits needed: none, 3, 6 or 9)

Returns
the formatted time
Here is the call graph for this function:

◆ hour()

unsigned anch::date::Time::hour ( ) const
constexprnoexcept

Hour getter

Returns
the hour (0 to 23)
Here is the call graph for this function:

◆ minute()

unsigned anch::date::Time::minute ( ) const
constexprnoexcept

Minute getter

Returns
the minute (0 to 59)
Here is the call graph for this function:

◆ nanosecond()

uint32_t anch::date::Time::nanosecond ( ) const
constexprnoexcept

Nanoseconds of the second getter

Returns
the nanoseconds (0 to 999999999)
Here is the call graph for this function:

◆ now()

Time anch::date::Time::now ( anch::date::Zone zone = anch::date::Zone::LOCAL)
static

Current time of day

Parameters
zonethe time zone (default local time)
Returns
the current time of day
Here is the call graph for this function:

◆ operator std::chrono::nanoseconds()

anch::date::Time::operator std::chrono::nanoseconds ( ) const
explicitconstexprnoexcept

Convert to the duration since midnight

Returns
the duration since midnight

◆ operator<=>()

std::strong_ordering anch::date::Time::operator<=> ( const Time & other) const
constexprnoexcept

Compare times

Parameters
otherthe other time
Returns
the chronological order in a day
Here is the call graph for this function:

◆ operator==()

bool anch::date::Time::operator== ( const Time & other) const
constexprnoexcept

Check times equality

Parameters
otherthe other time
Returns
true when times are equal
Here is the call graph for this function:

◆ parse()

Time anch::date::Time::parse ( std::string_view text)
static

Parse RFC 3339 partial-time ( HH:MM:SS[.fraction] , without offset)

Parameters
textthe text to parse
Returns
the time
Exceptions
std::invalid_argumentinvalid format, impossible time or leap second
Here is the call graph for this function:

◆ plus()

Time anch::date::Time::plus ( std::chrono::nanoseconds duration) const
noexcept

Add duration: the result wraps around midnight (23:00 plus 2 hours is 01:00)

Parameters
durationthe duration (negative to subtract)
Returns
the new time
Here is the call graph for this function:

◆ second()

unsigned anch::date::Time::second ( ) const
constexprnoexcept

Second getter

Returns
the second (0 to 59)
Here is the call graph for this function:

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