Time of day (RFC 3339 partial-time , SQL TIME , XSD xs:time without time zone).
More...
#include <time.hpp>
|
| 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 |
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;
std::cout << closing << " " << open << std::endl;
}
- Author
- Vincent Lachenal
- Since
- 0.3
◆ Time() [1/3]
| anch::date::Time::Time |
( |
| ) |
|
|
constexprnoexcept |
Time default constructor: midnight (00:00:00)
◆ Time() [2/3]
| anch::date::Time::Time |
( |
unsigned | hour, |
|
|
unsigned | minute, |
|
|
unsigned | second = 0, |
|
|
uint32_t | nanosecond = 0 ) |
Time constructor
- Parameters
-
| hour | the hour (0 to 23) |
| minute | the minute (0 to 59) |
| second | the second (0 to 59) |
| nanosecond | the nanoseconds of the second (0 to 999999999) |
- Exceptions
-
| std::invalid_argument | impossible time |
◆ Time() [3/3]
| anch::date::Time::Time |
( |
std::chrono::nanoseconds | sinceMidnight | ) |
|
|
explicit |
Time constructor
- Parameters
-
| sinceMidnight | the duration since midnight (less than 24 hours) |
- Exceptions
-
| std::invalid_argument | negative duration or duration of 24 hours or more |
◆ 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
◆ hour()
| unsigned anch::date::Time::hour |
( |
| ) |
const |
|
constexprnoexcept |
Hour getter
- Returns
- the hour (0 to 23)
◆ minute()
| unsigned anch::date::Time::minute |
( |
| ) |
const |
|
constexprnoexcept |
Minute getter
- Returns
- the minute (0 to 59)
◆ nanosecond()
| uint32_t anch::date::Time::nanosecond |
( |
| ) |
const |
|
constexprnoexcept |
Nanoseconds of the second getter
- Returns
- the nanoseconds (0 to 999999999)
◆ now()
Current time of day
- Parameters
-
| zone | the time zone (default local time) |
- Returns
- the current time of day
◆ 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
-
- Returns
- the chronological order in a day
◆ operator==()
| bool anch::date::Time::operator== |
( |
const Time & | other | ) |
const |
|
constexprnoexcept |
Check times equality
- Parameters
-
- Returns
true when times are equal
◆ parse()
| Time anch::date::Time::parse |
( |
std::string_view | text | ) |
|
|
static |
Parse RFC 3339 partial-time ( HH:MM:SS[.fraction] , without offset)
- Parameters
-
- Returns
- the time
- Exceptions
-
| std::invalid_argument | invalid format, impossible time or leap second |
◆ 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
-
| duration | the duration (negative to subtract) |
- Returns
- the new time
◆ second()
| unsigned anch::date::Time::second |
( |
| ) |
const |
|
constexprnoexcept |
Second getter
- Returns
- the second (0 to 59)
The documentation for this class was generated from the following file: