CodePorting.Translator Cs2Cpp
CodePorting.Translator.Cs2Cpp.Framework
date_time_offset.h
1
2#pragma once
3
4#include <system/date_time.h>
5#include <system/timespan.h>
6#include <system/boxable_traits.h>
7#include <functional>
8
9namespace System {
10
15class ASPOSECPP_SHARED_CLASS DateTimeOffset final
16{
17public:
19 static constexpr int64_t MaxOffset = TimeSpan::TicksPerHour * 14;
21 static constexpr int64_t MinOffset = -MaxOffset;
22
24 static ASPOSECPP_SHARED_API const DateTimeOffset MinValue;
26 static ASPOSECPP_SHARED_API const DateTimeOffset MaxValue;
28 static ASPOSECPP_SHARED_API const DateTimeOffset UnixEpoch;
29
31 constexpr DateTimeOffset() = default;
34 ASPOSECPP_SHARED_API DateTimeOffset(DateTime date_time);
38 ASPOSECPP_SHARED_API DateTimeOffset(int64_t ticks, TimeSpan offset);
42 ASPOSECPP_SHARED_API DateTimeOffset(DateTime date_time, TimeSpan offset);
51 ASPOSECPP_SHARED_API DateTimeOffset(int year, int month, int day, int hour, int minute, int second, TimeSpan offset);
61 ASPOSECPP_SHARED_API DateTimeOffset(int year, int month, int day, int hour, int minute, int second, int millisecond, TimeSpan offset);
72 ASPOSECPP_SHARED_API DateTimeOffset(int year, int month, int day, int hour, int minute, int second, int millisecond, const SharedPtr<Globalization::Calendar>& calendar, TimeSpan offset);
73
75 static ASPOSECPP_SHARED_API DateTimeOffset get_UtcNow();
77 static ASPOSECPP_SHARED_API DateTimeOffset get_Now();
78
80 ASPOSECPP_SHARED_API DateTime get_DateTime() const;
82 ASPOSECPP_SHARED_API DateTime get_UtcDateTime() const;
84 ASPOSECPP_SHARED_API DateTime get_LocalDateTime() const;
86 ASPOSECPP_SHARED_API DateTime get_Date() const;
88 ASPOSECPP_SHARED_API int get_Year() const;
90 ASPOSECPP_SHARED_API int get_Month() const;
92 ASPOSECPP_SHARED_API int get_Day() const;
94 ASPOSECPP_SHARED_API DayOfWeek get_DayOfWeek() const;
96 ASPOSECPP_SHARED_API int get_DayOfYear() const;
98 ASPOSECPP_SHARED_API int get_Hour() const;
100 ASPOSECPP_SHARED_API int get_Minute() const;
102 constexpr int get_Second() const { return m_date_time.get_Second(); }
104 constexpr int get_Millisecond() const { return m_date_time.get_Millisecond(); }
106 constexpr TimeSpan get_Offset() const { return m_offset; }
108 ASPOSECPP_SHARED_API int64_t get_Ticks() const;
110 ASPOSECPP_SHARED_API int64_t get_UtcTicks() const;
112 ASPOSECPP_SHARED_API TimeSpan get_TimeOfDay() const;
113
118 static ASPOSECPP_SHARED_API int Compare(const DateTimeOffset& first, const DateTimeOffset& second);
123 static ASPOSECPP_SHARED_API bool Equals(const DateTimeOffset& first, const DateTimeOffset& second);
127 static ASPOSECPP_SHARED_API DateTimeOffset FromFileTime(int64_t file_time);
131 static ASPOSECPP_SHARED_API DateTimeOffset FromUnixTimeMilliseconds(int64_t milliseconds);
135 static ASPOSECPP_SHARED_API DateTimeOffset FromUnixTimeSeconds(int64_t seconds);
139 static ASPOSECPP_SHARED_API DateTimeOffset Parse(const String& input);
152 static ASPOSECPP_SHARED_API DateTimeOffset ParseExact(const String& input, const String& format, const SharedPtr<IFormatProvider>& provider, Globalization::DateTimeStyles styles = Globalization::DateTimeStyles::None);
159 static ASPOSECPP_SHARED_API DateTimeOffset ParseExact(const String& input, const ArrayPtr<String>& formats, const SharedPtr<IFormatProvider>& provider, Globalization::DateTimeStyles styles);
164 static ASPOSECPP_SHARED_API bool TryParse(const String& input, DateTimeOffset& result);
171 static ASPOSECPP_SHARED_API bool TryParse(const String& input, const SharedPtr<IFormatProvider>& provider, Globalization::DateTimeStyles styles, DateTimeOffset& result);
179 static ASPOSECPP_SHARED_API bool TryParseExact(const String& input, const ArrayPtr<String>& formats, const SharedPtr<IFormatProvider>& provider, Globalization::DateTimeStyles styles, DateTimeOffset& result);
187 static ASPOSECPP_SHARED_API bool TryParseExact(const String& input, const String& format, const SharedPtr<IFormatProvider>& provider, Globalization::DateTimeStyles styles, DateTimeOffset& result);
191 ASPOSECPP_SHARED_API DateTimeOffset Add(TimeSpan value) const;
195 ASPOSECPP_SHARED_API DateTimeOffset AddYears(int years) const;
199 ASPOSECPP_SHARED_API DateTimeOffset AddMonths(int months) const;
203 ASPOSECPP_SHARED_API DateTimeOffset AddDays(double days) const;
207 ASPOSECPP_SHARED_API DateTimeOffset AddHours(double hours) const;
211 ASPOSECPP_SHARED_API DateTimeOffset AddMinutes(double minutes) const;
215 ASPOSECPP_SHARED_API DateTimeOffset AddSeconds(double seconds) const;
219 ASPOSECPP_SHARED_API DateTimeOffset AddMilliseconds(double milliseconds) const;
223 ASPOSECPP_SHARED_API DateTimeOffset AddTicks(int64_t ticks) const;
227 ASPOSECPP_SHARED_API int CompareTo(const DateTimeOffset& other) const;
231 ASPOSECPP_SHARED_API int CompareTo(const SharedPtr<Object>& obj) const;
235 ASPOSECPP_SHARED_API bool Equals(const DateTimeOffset& other) const;
239 ASPOSECPP_SHARED_API bool Equals(const SharedPtr<Object>& obj) const;
243 ASPOSECPP_SHARED_API bool EqualsExact(const DateTimeOffset& other) const;
247 ASPOSECPP_SHARED_API bool EqualsExact(const SharedPtr<Object>& obj) const;
251 ASPOSECPP_SHARED_API DateTimeOffset Subtract(TimeSpan value) const;
255 ASPOSECPP_SHARED_API TimeSpan Subtract(const DateTimeOffset& value) const;
258 ASPOSECPP_SHARED_API int64_t ToFileTime() const;
261 ASPOSECPP_SHARED_API DateTimeOffset ToLocalTime() const;
265 ASPOSECPP_SHARED_API DateTimeOffset ToOffset(TimeSpan offset) const;
270 ASPOSECPP_SHARED_API String ToString(const String& format, const SharedPtr<IFormatProvider>& provider) const;
274 ASPOSECPP_SHARED_API String ToString(const SharedPtr<IFormatProvider>& provider) const;
278 ASPOSECPP_SHARED_API String ToString(const String& format) const;
281 ASPOSECPP_SHARED_API DateTimeOffset ToUniversalTime() const;
284 ASPOSECPP_SHARED_API int64_t ToUnixTimeMilliseconds() const;
287 ASPOSECPP_SHARED_API int64_t ToUnixTimeSeconds() const;
288
291 ASPOSECPP_SHARED_API int GetHashCode() const;
294 ASPOSECPP_SHARED_API String ToString() const;
295
299 ASPOSECPP_SHARED_API DateTimeOffset operator+(TimeSpan value) const;
303 ASPOSECPP_SHARED_API DateTimeOffset operator-(TimeSpan value) const;
307 ASPOSECPP_SHARED_API TimeSpan operator-(const DateTimeOffset& other) const;
311 ASPOSECPP_SHARED_API bool operator==(const DateTimeOffset& other) const;
315 ASPOSECPP_SHARED_API bool operator!=(const DateTimeOffset& other) const;
319 ASPOSECPP_SHARED_API bool operator<(const DateTimeOffset& other) const;
323 ASPOSECPP_SHARED_API bool operator>(const DateTimeOffset& other) const;
327 ASPOSECPP_SHARED_API bool operator<=(const DateTimeOffset& other) const;
331 ASPOSECPP_SHARED_API bool operator>=(const DateTimeOffset& other) const;
332
334 static const TypeInfo& Type()
335 {
336 return *static_holder<ThisTypeInfo>();
337 }
338
339 constexpr bool IsNull() const { return false; }
340 constexpr bool operator==(std::nullptr_t) const { return false; }
341 constexpr bool operator!=(std::nullptr_t) const { return true; }
342 constexpr bool operator<(std::nullptr_t) const { return false; }
343 constexpr bool operator<=(std::nullptr_t) const { return false; }
344 constexpr bool operator>(std::nullptr_t) const { return false; }
345 constexpr bool operator>=(std::nullptr_t) const { return false; }
346
347private:
349 DateTime m_date_time;
351 TimeSpan m_offset;
352
353 struct ThisTypeInfo : TypeInfoPtr
354 {
355 ThisTypeInfo()
356 : TypeInfoPtr(u"System::DateTimeOffset")
357 {}
358 };
359};
360
361constexpr bool operator==(std::nullptr_t, const DateTimeOffset&) { return false; }
362constexpr bool operator!=(std::nullptr_t, const DateTimeOffset&) { return true; }
363constexpr bool operator<(std::nullptr_t, const DateTimeOffset&) { return false; }
364constexpr bool operator<=(std::nullptr_t, const DateTimeOffset&) { return false; }
365constexpr bool operator>(std::nullptr_t, const DateTimeOffset&) { return false; }
366constexpr bool operator>=(std::nullptr_t, const DateTimeOffset&) { return false; }
367
370template<> struct IsBoxable<DateTimeOffset> : std::true_type {};
372
374ASPOSECPP_SHARED_API void PrintTo(DateTimeOffset value, std::ostream* stream);
375
380inline std::ostream& operator<<(std::ostream& stream, DateTimeOffset value)
381{
382 stream << value.ToString();
383 return stream;
384}
385
390inline std::wostream& operator<<(std::wostream& stream, DateTimeOffset value)
391{
392 stream << value.ToString();
393 return stream;
394}
395
396} // namespace System
397
398namespace std {
399 template <>
400 class hash<System::DateTimeOffset>
401 {
402 public:
403 using argument_type = System::DateTimeOffset;
404 using result_type = std::size_t;
405
406 result_type operator()(const argument_type& value) const
407 {
408 return static_cast<result_type>(value.GetHashCode());
409 }
410 };
411}
Represents a specific date and time value on the time continuum. This type should be allocated on sta...
Definition: date_time.h:50
Contains the date and time of day relative to Coordinated Universal Time. Objects of this class shoul...
Definition: date_time_offset.h:16
static int Compare(const DateTimeOffset &first, const DateTimeOffset &second)
Compares two DateTimeOffset objects.
bool EqualsExact(const SharedPtr< Object > &obj) const
Checks if two DateTimeOffset objects represents the same time point and has the same offset.
bool operator>=(const DateTimeOffset &other) const
Determines if the current object represents the date and time value that is later than or the same as...
TimeSpan Subtract(const DateTimeOffset &value) const
Subtracts a specified DateTimeOffset value from the current object.
DateTime get_UtcDateTime() const
Gets DateTime value that represents the UTC date and time.
static const TypeInfo & Type()
Returns a TypeInfo object that represent TimeSpan structure.
Definition: date_time_offset.h:334
bool operator>(const DateTimeOffset &other) const
Determines if the current object represents the date and time value that is later than the value repr...
DayOfWeek get_DayOfWeek() const
Gets day of the week of the current object.
static DateTimeOffset FromUnixTimeMilliseconds(int64_t milliseconds)
Convert Unix-time to DateTimeOffset object.
DateTimeOffset(int year, int month, int day, int hour, int minute, int second, int millisecond, TimeSpan offset)
Constructor.
int GetHashCode() const
Gets hash code for the current DateTimeOffset object.
static DateTimeOffset ParseExact(const String &input, const ArrayPtr< String > &formats, const SharedPtr< IFormatProvider > &provider, Globalization::DateTimeStyles styles)
Converts the specified string to DateTimeOffset object using the specified formats,...
int CompareTo(const DateTimeOffset &other) const
Compares two DateTimeOffset objects.
int get_Day() const
Gets day of the month of the current object.
int64_t ToUnixTimeSeconds() const
Gets seconds elapsed from Unix epoch start.
bool operator!=(const DateTimeOffset &other) const
Determines if the current object and the specified DateTimeOffset object represent distinct date and ...
constexpr bool operator<(std::nullptr_t) const
Definition: date_time_offset.h:342
int get_Month() const
Gets month component of the current object.
DateTimeOffset ToOffset(TimeSpan offset) const
Replace current object offset by the specified offset.
bool operator==(const DateTimeOffset &other) const
Determines if the current object and the specified DateTimeOffset object represent the same date and ...
DateTime get_Date() const
Gets date component of the current object.
String ToString(const String &format) const
Converts current object to string using the specified format.
DateTimeOffset AddDays(double days) const
Adds a specified number of days to the DateTimeOffset object.
static DateTimeOffset Parse(const String &input, const SharedPtr< IFormatProvider > &provider, Globalization::DateTimeStyles styles=Globalization::DateTimeStyles::None)
Converts the specified string to DateTimeOffset object using the specified format provider and format...
DateTimeOffset AddTicks(int64_t ticks) const
Adds a specified number of ticks to the DateTimeOffset object.
int64_t ToFileTime() const
Converts current object to the Windows file time.
DateTimeOffset AddMilliseconds(double milliseconds) const
Adds a specified number of milliseconds to the DateTimeOffset object.
DateTimeOffset AddMonths(int months) const
Adds a specified number of months to the DateTimeOffset object.
static bool TryParse(const String &input, const SharedPtr< IFormatProvider > &provider, Globalization::DateTimeStyles styles, DateTimeOffset &result)
Tries to converts the specified string to DateTimeOffset object using the specified format provider a...
DateTime get_DateTime() const
Gets DateTime value.
constexpr bool operator==(std::nullptr_t) const
Definition: date_time_offset.h:340
String ToString() const
Converts current object to string.
int get_Year() const
Gets year component of the current object.
constexpr bool operator>(std::nullptr_t) const
Definition: date_time_offset.h:344
int64_t get_Ticks() const
Gets number of ticks of the current object.
static DateTimeOffset FromFileTime(int64_t file_time)
Convert Windows file time to date and time with local time offset.
DateTimeOffset AddMinutes(double minutes) const
Adds a specified number of minutes to the DateTimeOffset object.
static DateTimeOffset FromUnixTimeSeconds(int64_t seconds)
Convert Unix-time to DateTimeOffset object.
DateTime get_LocalDateTime() const
Gets DateTime value that represents the local date and time.
int CompareTo(const SharedPtr< Object > &obj) const
Compares two DateTimeOffset objects.
DateTimeOffset(int year, int month, int day, int hour, int minute, int second, int millisecond, const SharedPtr< Globalization::Calendar > &calendar, TimeSpan offset)
Constructor.
String ToString(const String &format, const SharedPtr< IFormatProvider > &provider) const
Converts current object to string using the specified format and format provider.
constexpr int get_Second() const
Gets second component of the current object.
Definition: date_time_offset.h:102
static DateTimeOffset Parse(const String &input)
Converts the specified string to DateTimeOffset equivalent.
bool operator<(const DateTimeOffset &other) const
Determines if the current object represents the date and time value that is earlier than the value re...
static DateTimeOffset get_UtcNow()
Gets DateTimeOffset whose date and time are set to the current UTC-time and whose offset is TimeSpan:...
DateTimeOffset operator+(TimeSpan value) const
Returns a new instance of DateTimeOffset class that represents the date and time value that is the su...
String ToString(const SharedPtr< IFormatProvider > &provider) const
Converts current object to string using the specified format provider.
DateTimeOffset AddYears(int years) const
Adds a specified number of years to the DateTimeOffset object.
constexpr DateTimeOffset()=default
Default constructor.
static bool Equals(const DateTimeOffset &first, const DateTimeOffset &second)
Checks if two DateTimeOffset objects represent the same time point.
bool EqualsExact(const DateTimeOffset &other) const
Checks if two DateTimeOffset objects represents the same time point and has the same offset.
DateTimeOffset ToLocalTime() const
Converts current object to a object that represents the local time,.
DateTimeOffset Add(TimeSpan value) const
Adds a specified time interval to the DateTimeOffset object.
static DateTimeOffset get_Now()
Gets DateTimeOffset whose date and time are set to the current local-time and whose offset is set to ...
static const DateTimeOffset MaxValue
Gets greatest DateTimeOffset value.
Definition: date_time_offset.h:26
DateTimeOffset operator-(TimeSpan value) const
Returns a new instance of the DateTimeOffset class representing the date and time value which is the ...
static const DateTimeOffset UnixEpoch
Gets Unix epoch start.
Definition: date_time_offset.h:28
DateTimeOffset(DateTime date_time, TimeSpan offset)
Constructor.
DateTimeOffset(DateTime date_time)
Constructor.
int get_DayOfYear() const
Gets day of year of the current object.
constexpr TimeSpan get_Offset() const
Gets offset from UTC.
Definition: date_time_offset.h:106
bool operator<=(const DateTimeOffset &other) const
Determines if the current object represents the date and time value that is earlier than or the same ...
static bool TryParseExact(const String &input, const String &format, const SharedPtr< IFormatProvider > &provider, Globalization::DateTimeStyles styles, DateTimeOffset &result)
Tries to converts the specified string to DateTimeOffset object using the specified format,...
TimeSpan get_TimeOfDay() const
Gets time of day of the current object.
constexpr bool IsNull() const
Definition: date_time_offset.h:339
constexpr bool operator<=(std::nullptr_t) const
Definition: date_time_offset.h:343
int get_Minute() const
Gets minute component of the current object.
bool Equals(const DateTimeOffset &other) const
Checks if two DateTimeOffset objects represents the same time point.
DateTimeOffset Subtract(TimeSpan value) const
Subtracts a specified time interval from the current object.
static bool TryParseExact(const String &input, const ArrayPtr< String > &formats, const SharedPtr< IFormatProvider > &provider, Globalization::DateTimeStyles styles, DateTimeOffset &result)
Tries to converts the specified string to DateTimeOffset object using the specified formats,...
DateTimeOffset AddHours(double hours) const
Adds a specified number of hours to the DateTimeOffset object.
int64_t ToUnixTimeMilliseconds() const
Gets milliseconds elapsed from Unix epoch start.
static const DateTimeOffset MinValue
Gets earliest DateTimeOffset value.
Definition: date_time_offset.h:24
DateTimeOffset(int year, int month, int day, int hour, int minute, int second, TimeSpan offset)
Constructor.
DateTimeOffset ToUniversalTime() const
Converts current object to a object that represents the UTC time,.
static bool TryParse(const String &input, DateTimeOffset &result)
Tries to converts the specified string to DateTimeOffset object.
static DateTimeOffset ParseExact(const String &input, const String &format, const SharedPtr< IFormatProvider > &provider, Globalization::DateTimeStyles styles=Globalization::DateTimeStyles::None)
Converts the specified string to DateTimeOffset object using the specified format,...
int64_t get_UtcTicks() const
Gets number of ticks of the current object in UTC time.
constexpr bool operator>=(std::nullptr_t) const
Definition: date_time_offset.h:345
DateTimeOffset(int64_t ticks, TimeSpan offset)
Constructor.
TimeSpan operator-(const DateTimeOffset &other) const
Returns an instance of TimeSpan class that represents the time interval between the date and time val...
constexpr bool operator!=(std::nullptr_t) const
Definition: date_time_offset.h:341
bool Equals(const SharedPtr< Object > &obj) const
Checks if two DateTimeOffset objects represents the same time point.
constexpr int get_Millisecond() const
Gets millisecond component of the current object.
Definition: date_time_offset.h:104
int get_Hour() const
Gets hour component of the current object.
DateTimeOffset AddSeconds(double seconds) const
Adds a specified number of seconds to the DateTimeOffset object.
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
static constexpr int64_t TicksPerHour
The number of 100-nanoseconds intervals in a hour.
Definition: timespan.h:71
Represents a particular type and provides information about it.
Definition: type_info.h:109
DateTimeStyles
Defines date and time formatting options. Bit flags.
Definition: date_time_styles.h:12
Definition: db_command.h:9
void PrintTo(DateTime value, std::ostream *stream)
Prints value to ostream. Mostly used for debug.
bool operator!=(ArraySegment< T > a, ArraySegment< T > b)
Definition: array_segment.h:157
constexpr bool operator>(std::nullptr_t, DateTime)
Definition: date_time.h:714
DayOfWeek
Enumeration that represents a day of week.
Definition: day_of_week.h:11
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