Stroika Library 3.0d16
 
Loading...
Searching...
No Matches
Stroika::Foundation::Time::TimeOfDay Class Reference

#include <TimeOfDay.h>

Public Types

enum class  NonStandardPrintFormat : uint8_t
 NonStandardPrintFormat is a representation which a TimeOfDay can be transformed into. More...
 

Public Member Functions

constexpr TimeOfDay (TimeOfDay &&src) noexcept=default
 
nonvirtual constexpr uint32_t GetAsSecondsCount () const
 
nonvirtual constexpr uint8_t GetHours () const
 
nonvirtual constexpr uint8_t GetMinutes () const
 
nonvirtual constexpr uint8_t GetSeconds () const
 
nonvirtual String Format (NonStandardPrintFormat pf=NonStandardPrintFormat::eDEFAULT) const
 
nonvirtual String ToString () const
 

Static Public Member Functions

static TimeOfDay Parse (const String &rep, const locale &l=locale{})
 
static optional< TimeOfDayParseQuietly (const String &rep, const String &formatPattern)
 like Parse(), but returns nullopt on parse error, not throwing exception. if locale is missing, and formatPattern is not locale independent, the current locale (locale{}) is used. if rep is empty, this will return nullopt
 

Static Public Attributes

static constexpr uint32_t kMaxSecondsPerDay = 60 * 60 * 24u
 
static constexpr string_view kISO8601Format = "%T"sv
 
static constexpr string_view kLocaleStandardFormat = "%X"sv
 
static constexpr string_view kLocaleStandardAlternateFormat = "%EX"sv
 
static const Traversal::Iterable< StringkDefaultParseFormats
 
static const TimeOfDay kMin {0}
 
static const TimeOfDay kMax {TimeOfDay::kMaxSecondsPerDay - 1}
 

Detailed Description

Description: A time value - which is assumed to be within a given day - e.g 2:30 pm.

TimeOfDay precision is up to the second (use TimePointSeconds for more precision).

Note
this implies NO NOTION of timezone. Its a time relative to midnight of a given day.
Thread-Safety C++-Standard-Thread-Safety
Comparisons: static_assert (totally_ordered<TimeOfDay>);

Definition at line 63 of file TimeOfDay.h.

Member Enumeration Documentation

◆ NonStandardPrintFormat

NonStandardPrintFormat is a representation which a TimeOfDay can be transformed into.

eCurrentLocale_WithZerosStripped eCurrentLocale_WithZerosStripped is eCurrentLocale, but with many cases of trailing zero's, and sometimes leading zeros, stripped, so for example, 01:03:05 PM will become 1:03:05 PM, and 04:06:00 PM will become 4:06 PM.

Definition at line 224 of file TimeOfDay.h.

Constructor & Destructor Documentation

◆ TimeOfDay()

constexpr Stroika::Foundation::Time::TimeOfDay::TimeOfDay ( TimeOfDay &&  src)
constexprdefaultnoexcept

If value out of range - pinned to kMax. We normalize to be within a given day (seconds since midnight)

For the TimeOfDay, we allow out of range values and pin/accumulate. But you can still never have a time of day >= kMaxSecondsPerDay. And the first hour (1pm) is hour 0, so TimeOfDay{2, 0, 0} is 3am.

if DataExchange::ValidationStrategy is NOT specified, or == DataExchange::ValidationStrategy::eAssertion, then

Precondition
argument time-of-day (in seconds or hours/minutes/seconds) is in valid range for one day
t < kMaxSecondsPerDay
hour < 24
minute < 60
seconds <= 60 (note <= not < due to leap seconds) else if validationStrategy == eThrow, then check and throw if out of range.

Member Function Documentation

◆ Parse()

TimeOfDay TimeOfDay::Parse ( const String rep,
const locale &  l = locale{} 
)
static

Always produces a valid legal TimeOfDay, or throws an exception.

Note
an empty string produces FormatException exception (whereas before 2.1d11 it produced an empty TimeOfDay object (TimeOfDay {}).
the 2 argument locale overload uses each of kDefaultParseFormats formats to try to parse the time string, but the default is locale specific standard time format.
overloads with the locale missing, default to locale{} - the default locale.
format strings defined by https://en.cppreference.com/w/cpp/locale/time_get/get and https://en.cppreference.com/w/cpp/locale/time_put/put
See also
https://en.cppreference.com/w/cpp/locale/time_get/get for allowed formatPatterns

The overload which takes a locale but no explicit format strings, defaults to trying each of kDefaultParseFormats strings in order, and returns the first match.

The overload taking an iterable of formats, tries each, and returns the timeofday for the first that succeeds, or throws FormatException if none succeed.

Definition at line 176 of file TimeOfDay.cpp.

◆ GetAsSecondsCount()

constexpr unsigned int Stroika::Foundation::Time::TimeOfDay::GetAsSecondsCount ( ) const
constexpr
Postcondition
{return} < kMaxSecondsPerDay

Definition at line 25 of file TimeOfDay.inl.

◆ GetHours()

constexpr uint8_t Stroika::Foundation::Time::TimeOfDay::GetHours ( ) const
constexpr

returns 0..23

Definition at line 30 of file TimeOfDay.inl.

◆ GetMinutes()

constexpr uint8_t Stroika::Foundation::Time::TimeOfDay::GetMinutes ( ) const
constexpr

returns 0..59

Definition at line 36 of file TimeOfDay.inl.

◆ GetSeconds()

constexpr uint8_t Stroika::Foundation::Time::TimeOfDay::GetSeconds ( ) const
constexpr

returns 0..59

Definition at line 44 of file TimeOfDay.inl.

◆ Format()

String TimeOfDay::Format ( NonStandardPrintFormat  pf = NonStandardPrintFormat::eDEFAULT) const

For formatPattern, see http://en.cppreference.com/w/cpp/locale/time_put/put If only formatPattern specified, and no locale, use default (global) locale.

Note
if locale is missing (not specified as argument) the default locale (locale{}) is used.

Definition at line 303 of file TimeOfDay.cpp.

◆ ToString()

String Stroika::Foundation::Time::TimeOfDay::ToString ( ) const
See also
Characters::ToString ()

Definition at line 52 of file TimeOfDay.inl.

Member Data Documentation

◆ kMaxSecondsPerDay

constexpr uint32_t Stroika::Foundation::Time::TimeOfDay::kMaxSecondsPerDay = 60 * 60 * 24u
staticconstexpr

NB: The maximum value in a TimeOfDay struct is one less than kMaxSecondsPerDay

Definition at line 68 of file TimeOfDay.h.

◆ kISO8601Format

constexpr string_view Stroika::Foundation::Time::TimeOfDay::kISO8601Format = "%T"sv
staticconstexpr
Note
https://en.cppreference.com/w/cpp/locale/time_get/get and https://en.cppreference.com/w/cpp/locale/time_put/put equivalent to "%H:%M:%S"
leading zeros in hours, minutes, seconds, required, not optional
this is locale-independent

Definition at line 107 of file TimeOfDay.h.

◆ kLocaleStandardFormat

constexpr string_view Stroika::Foundation::Time::TimeOfDay::kLocaleStandardFormat = "%X"sv
staticconstexpr

◆ kLocaleStandardAlternateFormat

constexpr string_view Stroika::Foundation::Time::TimeOfDay::kLocaleStandardAlternateFormat = "%EX"sv
staticconstexpr

◆ kDefaultParseFormats

const Traversal::Iterable< String > Stroika::Foundation::Time::TimeOfDay::kDefaultParseFormats
static
Initial value:
{
"%r"sv,
"%H:%M"sv,
"%I%p"sv,
"%I%P"sv,
"%I%t%p"sv,
"%I%t%P"sv,
"%I:%M%t%p"sv,
"%I:%M%t%P"sv,
"%I:%M:%S%t%p"sv,
"%I:%M:%S%t%P"sv,
"%I:%M:%S"sv,
"%I:%M"sv,
}
static constexpr string_view kISO8601Format
Definition TimeOfDay.h:107
static constexpr string_view kLocaleStandardFormat
Definition TimeOfDay.h:113
static constexpr string_view kLocaleStandardAlternateFormat
Definition TimeOfDay.h:119

Default formats used by TimeOfDay::Parse () to parse time strings. The first of these - X, is the locale-specific time format.

Note
https://en.cppreference.com/w/cpp/locale/time_get/get and https://en.cppreference.com/w/cpp/locale/time_put/put

Definition at line 128 of file TimeOfDay.h.

◆ kMin

constexpr TimeOfDay Stroika::Foundation::Time::TimeOfDay::kMin {0}
staticconstexpr

kMin is the first date this TimeOfDay class supports representing.

Definition at line 174 of file TimeOfDay.h.

◆ kMax

constexpr TimeOfDay Stroika::Foundation::Time::TimeOfDay::kMax {TimeOfDay::kMaxSecondsPerDay - 1}
staticconstexpr

kMax is the last date this TimeOfDay class supports representing. This is a legal TimeOfDay, and not like 'end' - one past the last legal value.

Definition at line 181 of file TimeOfDay.h.


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