4#include "Stroika/Foundation/StroikaPreComp.h"
10#include "Stroika/Foundation/Characters/FloatConversion.h"
14#include "Stroika/Foundation/Linguistics/MessageUtilities.h"
15#include "Stroika/Foundation/Math/Common.h"
21using namespace Stroika::Foundation::Time;
35Duration::FormatException::FormatException ()
36 : inherited{
"Invalid Duration Format"sv}
47 constexpr wstring_view kMS_ = L
"\u00b5s"sv;
48 static_assert (kMS_.size () == 2 && kMS_[0] == 0x00B5 and kMS_[1] ==
's');
51const Duration::PrettyPrintInfo Duration::kDefaultPrettyPrintInfo = {{
52 "year"sv,
"years"sv,
"month"sv,
"months"sv,
"week"sv,
"weeks"sv,
"day"sv,
"days"sv,
"hour"sv,
"hours"sv,
"minute"sv,
53 "minutes"sv,
"second"sv,
"seconds"sv,
"ms"sv,
"ms"sv, kMS_, kMS_,
"ns"sv,
"ns"sv,
"ps"sv,
"ps"sv,
56const Duration::AgePrettyPrintInfo Duration::kDefaultAgePrettyPrintInfo = {
78 string::const_iterator SkipWhitespace_ (string::const_iterator i, string::const_iterator end)
82 while (i != end and isspace (*i)) {
88 string::const_iterator FindFirstNonDigitOrDot_ (string::const_iterator i, string::const_iterator end)
90 while (i != end and (isdigit (*i) or *i ==
'.')) {
97 constexpr time_t kSecondsPerMinute_ = 60;
98 constexpr time_t kSecondsPerHour_ = kSecondsPerMinute_ * 60;
99 constexpr time_t kSecondsPerDay_ = kSecondsPerHour_ * 24;
100 constexpr time_t kSecondsPerWeek_ = kSecondsPerDay_ * 7;
101 constexpr time_t kSecondsPerMonth_ = kSecondsPerDay_ * 30;
102 constexpr time_t kSecondsPerYear_ = kSecondsPerDay_ * 365;
107 auto lingMgr = Linguistics::MessageUtilities::Manager::sThe.LookupHandler ();
121 InternalNumericFormatType_
timeLeft =
t < 0 ? -
t :
t;
272 if (result.
empty ()) {
277 result =
kNeg_ + result;
336Duration::InternalNumericFormatType_ Duration::ParseTime_ (
const string& s)
338#if USE_NOISY_TRACE_IN_THIS_MODULE_
342 return kValueWhenEmptyRenderedAsNumber_;
344 InternalNumericFormatType_
curVal = 0;
352 if (*i ==
'P') [[
likely]] {
356 Throw (FormatException::kThe);
359 while (i !=
s.end ()) {
368 Throw (FormatException::kThe);
371 Throw (FormatException::kThe);
410#if USE_NOISY_TRACE_IN_THIS_MODULE_
413 Require (
not isnan (
t));
415 InternalNumericFormatType_
timeLeft =
t < 0 ? -
t :
t;
481 using namespace FloatConversion;
486 if (result.
length () == 1) {
497namespace Stroika::Foundation::Math {
500 return (v.count () < 0) ? -v : v;
#define qStroika_ATTRIBUTE_INDETERMINATE
qStroika_ATTRIBUTE_INDETERMINATE is used where you would use a C++ attribute for a variable that is i...
Similar to String, but intended to more efficiently construct a String. Mutable type (String is large...
nonvirtual size_t length() const noexcept
number of characters, not bytes or code-points
nonvirtual bool empty() const noexcept
String is like std::u32string, except it is much easier to use, often much more space efficient,...
Duration is a chrono::duration<double> (=.
nonvirtual Duration & operator+=(const Duration &rhs)
nonvirtual Characters::String PrettyPrintAge(const AgePrettyPrintInfo &agePrettyPrintInfo=kDefaultAgePrettyPrintInfo, const PrettyPrintInfo &prettyPrintInfo=kDefaultPrettyPrintInfo) const
nonvirtual Characters::String PrettyPrint(const PrettyPrintInfo &prettyPrintInfo=kDefaultPrettyPrintInfo) const
nonvirtual Duration operator-() const
@ eStandard
Somewhat like defaultfloat, but never uses scientific notation.
STRING_TYPE ToString(FLOAT_TYPE f, const ToStringOptions &options={})
void Throw(T &&e2Throw)
identical to builtin C++ 'throw' except that it does helpful, type dependent DbgTrace() messages firs...