5#include <system/string.h>
6#include <system/boxable_traits.h>
7#include <system/iformatprovider.h>
8#include <system/globalization/time_span_styles.h>
13namespace Globalization {
15 class DateTimeFormatInfo;
69 static constexpr int64_t TicksPerDay = 864000000000ULL;
71 static constexpr int64_t TicksPerHour = 36000000000ULL;
73 static constexpr int64_t TicksPerMillisecond = 10000ULL;
75 static constexpr int64_t TicksPerMinute = 600000000ULL;
77 static constexpr int64_t TicksPerSecond = 10000000ULL;
85 explicit constexpr TimeSpan(int64_t ticks) : m_ticks(ticks) {}
91 ASPOSECPP_SHARED_API
TimeSpan(
int hours,
int minutes,
int seconds);
99 ASPOSECPP_SHARED_API
TimeSpan(
int days,
int hours,
int minutes,
int seconds,
int milliseconds = 0);
121 return Interval(value, 1);
129 constexpr int MillisecondsPerSecond = 1000;
130 return Interval(value, MillisecondsPerSecond);
138 constexpr int MillisecondsPerMinute = 60 * 1000;
139 return Interval(value, MillisecondsPerMinute);
147 constexpr int MillisecondsPerHour = 60 * 60 * 1000;
148 return Interval(value, MillisecondsPerHour);
156 constexpr int MillisecondsPerDay = 24 * 60 * 60 * 1000;
157 return Interval(value, MillisecondsPerDay);
166 if (t1.m_ticks > t2.m_ticks)
return 1;
167 if (t1.m_ticks < t2.m_ticks)
return -1;
189 return m_ticks == value.m_ticks;
200 return a.m_ticks == b.m_ticks;
209 return static_cast<int>(m_ticks / TicksPerDay);
215 return static_cast<int>((m_ticks / TicksPerHour) % 24);
221 return static_cast<int>((m_ticks / TicksPerMinute) % 60);
227 return static_cast<int>((m_ticks / TicksPerSecond) % 60);
233 return static_cast<int>((m_ticks / TicksPerMillisecond) % 1000);
245 return static_cast<double>(m_ticks) / TicksPerDay;
251 return static_cast<double>(m_ticks) / TicksPerHour;
257 return static_cast<double>(m_ticks) / TicksPerMinute;
263 return static_cast<double>(m_ticks) / TicksPerSecond;
417 return *
this = Add(value);
425 return Subtract(value);
433 return *
this = Subtract(value);
457 return m_ticks /
static_cast<double>(value.m_ticks);
465 return m_ticks == value.m_ticks;
473 return m_ticks != value.m_ticks;
481 return m_ticks < value.m_ticks;
489 return m_ticks <= value.m_ticks;
497 return m_ticks > value.m_ticks;
505 return m_ticks >= value.m_ticks;
511 return *static_holder<ThisTypeInfo>();
514 constexpr bool IsNull()
const {
return false; }
515 constexpr bool operator==(std::nullptr_t)
const {
return false; }
516 constexpr bool operator!=(std::nullptr_t)
const {
return true; }
517 constexpr bool operator<(std::nullptr_t)
const {
return false; }
518 constexpr bool operator<=(std::nullptr_t)
const {
return false; }
519 constexpr bool operator>(std::nullptr_t)
const {
return false; }
520 constexpr bool operator>=(std::nullptr_t)
const {
return false; }
539 static ASPOSECPP_SHARED_API TimeSpan Interval(
double value,
int scale);
541#if defined(_DEBUG) && defined(_MSC_VER)
544 struct Days { int64_t ticks; };
545 struct HoursMinutes { int64_t ticks; };
546 struct HoursMinutesSeconds { int64_t ticks; };
547 struct Fraction { int64_t ticks; };
562template<>
struct IsBoxable<TimeSpan> : std::true_type {};
592 class hash<
System::TimeSpan>
596 using result_type = std::size_t;
598 result_type operator()(argument_type value)
const
600 return static_cast<result_type
>(value.GetHashCode());
Pointer class to wrap types being allocated on heap. Use it to manage memory for classes inheriting O...
Definition: smart_ptr.h:180
String class used across the library. Is a substitute for C# System.String when translating code....
Definition: string.h:122
Represents a time interval. This type should be allocated on stack and passed to functions by value o...
Definition: timespan.h:59
constexpr bool IsNull() const
Definition: timespan.h:514
TimeSpan Negate() const
Returns a new instance of TimeSpan object that represents negated value represented by the current Ti...
constexpr double get_TotalHours() const
Returns the value of the current TimeSpan object expressed in whole and fractional hours.
Definition: timespan.h:249
TimeSpan(int hours, int minutes, int seconds)
Constructs an instance of TimeSpan class that represents the time interval which is equal to the sum ...
static bool TryParseExact(const String &input, const String &format, std::nullptr_t, Globalization::TimeSpanStyles styles, TimeSpan &result)
constexpr double operator/(TimeSpan value) const
Definition: timespan.h:455
static TimeSpan ParseExact(const String &input, const ArrayPtr< String > &formats, const SharedPtr< Globalization::CultureInfo > &culture, Globalization::TimeSpanStyles styles=Globalization::TimeSpanStyles::None)
static TimeSpan Parse(const String &input, std::nullptr_t)
Definition: timespan.h:311
TimeSpan Subtract(TimeSpan value) const
Returns a new instance of TimeSpan class that represents a time interval which is the result of subtr...
static bool TryParseExact(const String &input, const String &format, std::nullptr_t, TimeSpan &result)
constexpr bool operator<(std::nullptr_t) const
Definition: timespan.h:517
constexpr bool Equals(TimeSpan value) const
Determines if the time interval represented by the current object is equal to the time interval repre...
Definition: timespan.h:187
static TimeSpan FromHours(double value)
Returns a new TimeSpan object that represents the specified interval.
Definition: timespan.h:145
String ToString(const String &format, std::nullptr_t) const
Definition: timespan.h:296
TimeSpan & operator+=(TimeSpan value)
Assigns to the current object the time interval which is the sum of the time interval represented by ...
Definition: timespan.h:415
TimeSpan Duration() const
Returns a new instance of TimeSpan object whose value is the absolute value of the current object.
static TimeSpan ParseExact(const String &input, const ArrayPtr< String > &formats, const SharedPtr< IFormatProvider > &provider, Globalization::TimeSpanStyles styles=Globalization::TimeSpanStyles::None)
Converts string to equivalent TimeSpan object using the specified formats, format provider and styles...
static TimeSpan ParseExact(const String &input, const ArrayPtr< String > &formats, std::nullptr_t, Globalization::TimeSpanStyles styles=Globalization::TimeSpanStyles::None)
static TimeSpan Parse(const String &input, const SharedPtr< Globalization::DateTimeFormatInfo > &dtfi)
TimeSpan & operator/=(double divisor)
Definition: timespan.h:450
static bool TryParseExact(const String &input, const String &format, const SharedPtr< Globalization::DateTimeFormatInfo > &dtfi, TimeSpan &result)
static TimeSpan ParseExact(const String &input, const String &format, const SharedPtr< Globalization::DateTimeFormatInfo > &dtfi, Globalization::TimeSpanStyles styles=Globalization::TimeSpanStyles::None)
constexpr TimeSpan & operator=(const TimeSpan &)=default
Sets the time interval represented by the specified TimeSpan object to the current TimeSpan object.
TimeSpan Add(TimeSpan value) const
Returns a new instance of TimeSpan class that represents a time interval which is the sum of the time...
String ToString() const
Returns the string representation of the time interval represented by the current object.
constexpr bool operator>(TimeSpan value) const
Determines if the time interval represented by the current object is longer than the time interval re...
Definition: timespan.h:495
static TimeSpan FromSeconds(double value)
Returns a new TimeSpan object that represents the specified interval.
Definition: timespan.h:127
constexpr bool operator==(TimeSpan value) const
Determines if the time interval represented by the current object is equal to the time interval repre...
Definition: timespan.h:463
static bool TryParseExact(const String &input, const ArrayPtr< String > &formats, const SharedPtr< Globalization::CultureInfo > &culture, Globalization::TimeSpanStyles styles, TimeSpan &result)
constexpr double get_TotalDays() const
Returns the value of the current TimeSpan object expressed in whole and fractional days.
Definition: timespan.h:243
static bool TryParseExact(const String &input, const ArrayPtr< String > &formats, const SharedPtr< Globalization::CultureInfo > &culture, TimeSpan &result)
static bool TryParseExact(const String &input, const ArrayPtr< String > &formats, std::nullptr_t, TimeSpan &result)
static constexpr bool Equals(TimeSpan a, TimeSpan b)
Returns true if the specified objects represent the same time interval, otherwise - false.
Definition: timespan.h:198
TimeSpan(int days, int hours, int minutes, int seconds, int milliseconds=0)
Constructs an instance of TimeSpan class that represents the time interval which is equal to the sum ...
constexpr TimeSpan()
Constructs a TimeSpan object that represents a zero time interval.
Definition: timespan.h:80
static const TimeSpan Zero
The TimeSpan object that represents zero-interval.
Definition: timespan.h:62
double get_TotalMilliseconds() const
Returns the value of the current TimeSpan object expressed in whole and fractional milliseconds.
static bool TryParseExact(const String &input, const ArrayPtr< String > &formats, const SharedPtr< IFormatProvider > &provider, Globalization::TimeSpanStyles styles, TimeSpan &result)
Converts string to equivalent TimeSpan object using the specified formats, format provider and styles...
static const TimeSpan MinValue
/// The TimeSpan object that represents the shortest possible interval.
Definition: timespan.h:66
static bool TryParseExact(const String &input, const String &format, const SharedPtr< Globalization::CultureInfo > &culture, Globalization::TimeSpanStyles styles, TimeSpan &result)
constexpr bool operator<=(TimeSpan value) const
Determines if the time interval represented by the current object is shorter than or equal to the tim...
Definition: timespan.h:487
constexpr int CompareTo(TimeSpan value) const
Compares current and the specified objects.
Definition: timespan.h:174
constexpr bool operator>=(TimeSpan value) const
Determines if the time interval represented by the current object is longer than or equal to the time...
Definition: timespan.h:503
static TimeSpan ParseExact(const String &input, const String &format, std::nullptr_t, Globalization::TimeSpanStyles styles=Globalization::TimeSpanStyles::None)
static constexpr TimeSpan FromTicks(int64_t ticks)
Returns a new TimeSpan object that represents the specified interval.
Definition: timespan.h:111
String ToString(const String &format, const SharedPtr< Globalization::DateTimeFormatInfo > &dtfi) const
static bool TryParseExact(const String &input, const ArrayPtr< String > &formats, const SharedPtr< Globalization::DateTimeFormatInfo > &dtfi, TimeSpan &result)
constexpr bool operator!=(std::nullptr_t) const
Definition: timespan.h:516
static TimeSpan Parse(const String &input, const SharedPtr< Globalization::CultureInfo > &culture)
static TimeSpan Parse(const String &input)
Converts string to equivalent TimeSpan object.
TimeSpan operator+(TimeSpan value) const
Returns a new instance of TimeSpan class that represents a time interval which is the sum of the time...
Definition: timespan.h:407
static bool TryParse(const String &input, TimeSpan &result)
Converts string to equivalent TimeSpan object and returns result of conversion.
static bool TryParseExact(const String &input, const String &format, const SharedPtr< Globalization::CultureInfo > &culture, TimeSpan &result)
constexpr int get_Minutes() const
Returns the minutes component of the time interval represented by the current TimeSpan object.
Definition: timespan.h:219
constexpr double get_TotalSeconds() const
Returns the value of the current TimeSpan object expressed in whole and fractional seconds.
Definition: timespan.h:261
constexpr int64_t get_Ticks() const
Returns the number of 100-nanoseconds intervals that constitute the time interval represented by the ...
Definition: timespan.h:237
String ToString(const String &format) const
Converts the value of the current object to equivalent string representation, using the specified for...
TimeSpan operator-() const
Returns a new instance of TimeSpan object that represents negated value represented by the current Ti...
Definition: timespan.h:437
constexpr bool operator<=(std::nullptr_t) const
Definition: timespan.h:518
int CompareTo(const SharedPtr< Object > &obj) const
Compares current and the specified objects.
static TimeSpan FromDays(double value)
Returns a new TimeSpan object that represents the specified interval.
Definition: timespan.h:154
constexpr bool operator>(std::nullptr_t) const
Definition: timespan.h:519
static bool TryParseExact(const String &input, const String &format, const SharedPtr< IFormatProvider > &provider, TimeSpan &result)
Converts string to equivalent TimeSpan object using the specified format and format provider,...
static const TypeInfo & Type()
Returns a TypeInfo object that represent TimeSpan structure.
Definition: timespan.h:509
static bool TryParse(const String &input, const SharedPtr< IFormatProvider > &provider, TimeSpan &result)
Converts string to equivalent TimeSpan object using the specified format provider and returns result ...
constexpr int get_Hours() const
Returns the hours component of the time interval represented by the current TimeSpan object.
Definition: timespan.h:213
static TimeSpan Parse(const String &input, const SharedPtr< IFormatProvider > &provider)
Converts string to equivalent TimeSpan object using the specified format provider.
static const TimeSpan MaxValue
The TimeSpan object that represents the longest possible interval.
Definition: timespan.h:64
TimeSpan operator-(TimeSpan value) const
Returns a new instance of TimeSpan class that represents a time interval which is the result of subtr...
Definition: timespan.h:423
TimeSpan operator+() const
Returns self.
Definition: timespan.h:443
constexpr TimeSpan(const TimeSpan &)=default
Constructs a TimeSpan object that represents the time interval equal to the time interval represented...
constexpr bool operator>=(std::nullptr_t) const
Definition: timespan.h:520
TimeSpan & operator-=(TimeSpan value)
Assigns to the current object the time interval which is the result of subtraction of the time interv...
Definition: timespan.h:431
constexpr bool operator!=(TimeSpan value) const
Determines if the time interval represented by the current object is not equal to the time interval r...
Definition: timespan.h:471
int GetHashCode() const
Returns a hash code for the current object.
constexpr double get_TotalMinutes() const
Returns the value of the current TimeSpan object expressed in whole and fractional minutes.
Definition: timespan.h:255
static TimeSpan ParseExact(const String &input, const ArrayPtr< String > &formats, const SharedPtr< Globalization::DateTimeFormatInfo > &dtfi, Globalization::TimeSpanStyles styles=Globalization::TimeSpanStyles::None)
static bool TryParseExact(const String &input, const ArrayPtr< String > &formats, const SharedPtr< Globalization::DateTimeFormatInfo > &dtfi, Globalization::TimeSpanStyles styles, TimeSpan &result)
String ToString(const String &format, const SharedPtr< IFormatProvider > &provider) const
Converts the value of the current object to equivalent string representation, using the specified for...
String ToString(const String &format, const SharedPtr< Globalization::CultureInfo > &culture) const
static bool TryParseExact(const String &input, const ArrayPtr< String > &formats, const SharedPtr< IFormatProvider > &provider, TimeSpan &result)
Converts string to equivalent TimeSpan object using the specified formats and format provider,...
constexpr int get_Days() const
Returns the days component of the time interval represented by the current TimeSpan object.
Definition: timespan.h:207
constexpr TimeSpan(int64_t ticks)
Constructs an instance of TimeSpan class that represents the specified time interval.
Definition: timespan.h:85
static TimeSpan ParseExact(const String &input, const String &format, const SharedPtr< IFormatProvider > &provider, Globalization::TimeSpanStyles styles=Globalization::TimeSpanStyles::None)
Converts string to equivalent TimeSpan object using the specified format, format provider and styles.
static TimeSpan FromMilliseconds(double value)
Returns a new TimeSpan object that represents the specified interval.
Definition: timespan.h:119
static bool TryParse(const String &input, const SharedPtr< Globalization::CultureInfo > &culture, TimeSpan &result)
static TimeSpan ParseExact(const String &input, const String &format, const SharedPtr< Globalization::CultureInfo > &culture, Globalization::TimeSpanStyles styles=Globalization::TimeSpanStyles::None)
static bool TryParseExact(const String &input, const ArrayPtr< String > &formats, std::nullptr_t, Globalization::TimeSpanStyles styles, TimeSpan &result)
static bool TryParse(const String &input, const SharedPtr< Globalization::DateTimeFormatInfo > &dtfi, TimeSpan &result)
static bool TryParseExact(const String &input, const String &format, const SharedPtr< Globalization::DateTimeFormatInfo > &dtfi, Globalization::TimeSpanStyles styles, TimeSpan &result)
static bool TryParseExact(const String &input, const String &format, const SharedPtr< IFormatProvider > &provider, Globalization::TimeSpanStyles styles, TimeSpan &result)
Converts string to equivalent TimeSpan object using the specified format, format provider and styles,...
static bool TryParse(const String &input, std::nullptr_t, TimeSpan &result)
constexpr bool operator==(std::nullptr_t) const
Definition: timespan.h:515
constexpr int get_Milliseconds() const
Returns the milliseconds component of the time interval represented by the current TimeSpan object.
Definition: timespan.h:231
static TimeSpan FromMinutes(double value)
Returns a new TimeSpan object that represents the specified interval.
Definition: timespan.h:136
static constexpr int Compare(TimeSpan t1, TimeSpan t2)
Compares two TimeSpan objects.
Definition: timespan.h:164
bool Equals(const SharedPtr< Object > &obj) const
Determines if the time interval represented by the current object is equal to the time interval repre...
constexpr int get_Seconds() const
Returns the seconds component of the time interval represented by the current TimeSpan object.
Definition: timespan.h:225
constexpr bool operator<(TimeSpan value) const
Determines if the time interval represented by the current object is shorter than the time interval r...
Definition: timespan.h:479
TimeSpan operator/(double divisor) const
Represents a particular type and provides information about it.
Definition: type_info.h:109
TimeSpanStyles
Specifies the formatting options that customize string parsing for methods that convert a string repr...
Definition: time_span_styles.h:12
@ None
The time interval represented by the inptut string is interpreted as a negative time interval only if...
Definition: db_command.h:9
void PrintTo(DateTime value, std::ostream *stream)
Prints value to ostream. Mostly used for debug.
std::enable_if_t<!std::is_floating_point< TA >::value &&!std::is_floating_point< TB >::value, int > Compare(const TA &a, const TB &b)
Compares two values.
Definition: primitive_types.h:113
bool operator!=(ArraySegment< T > a, ArraySegment< T > b)
Definition: array_segment.h:157
Decimal operator/(const T &x, const Decimal &d)
Returns a new instance of Decimal class that represents a value that is a result of division of the s...
Definition: decimal.h:563
constexpr bool operator>(std::nullptr_t, DateTime)
Definition: date_time.h:714
std::ostream & operator<<(std::ostream &stream, DateTime date_time)
Insert data into the stream using UTF-8 encoding.
Definition: date_time.h:729
constexpr bool operator<(std::nullptr_t, DateTime)
Definition: date_time.h:712
constexpr bool operator<=(std::nullptr_t, DateTime)
Definition: date_time.h:713
constexpr bool operator>=(std::nullptr_t, DateTime)
Definition: date_time.h:715
bool operator==(ArraySegment< T > a, ArraySegment< T > b)
Definition: array_segment.h:151
Wrapper for a pointer to an instance of TypeInfo class. This type should be allocated on stack and pa...
Definition: type_info.h:72