5#include <system/date_time_kind.h>
6#include <system/day_of_week.h>
7#include <system/timespan.h>
8#include <system/boxable_traits.h>
9#include <system/globalization/date_time_styles.h>
15namespace Globalization {
18 class DateTimeFormatInfo;
54 static constexpr int64_t TicksPerMicrosecond = 10;
56 static constexpr int64_t TicksPerMillisecond = 10000;
58 static constexpr int64_t TicksPerSecond = TicksPerMillisecond * 1000;
60 static constexpr int64_t TicksPerMinute = TicksPerSecond * 60;
62 static constexpr int64_t TicksPerHour = TicksPerMinute * 60;
64 static constexpr int64_t TicksPerDay = TicksPerHour * 24;
67 static constexpr int64_t MinTicks = 0;
69 static constexpr int64_t MaxTicks = 3652059 * TicksPerDay - 1;
87 ASPOSECPP_SHARED_API
DateTime(
int year,
int month,
int day);
103 ASPOSECPP_SHARED_API
DateTime(
int year,
int month,
int day,
int hour,
int minute,
int second);
113 ASPOSECPP_SHARED_API
DateTime(
int year,
int month,
int day,
int hour,
int minute,
int second,
DateTimeKind kind);
171 const int64_t ticks = get_Ticks();
172 return DateTime(
static_cast<uint64_t
>(ticks - (ticks % TicksPerDay)) | Flags(), InternalConstructor);
178 return static_cast<DayOfWeek>((get_Ticks() / TicksPerDay + 1) % 7);
184 return static_cast<DateTimeKind>(std::min(2,
static_cast<int>(m_data >> 62)));
190 return TimeSpan(get_Ticks() % TicksPerDay);
211 return static_cast<int>((get_Ticks() / TicksPerHour) % 24);
217 return static_cast<int>((get_Ticks() / TicksPerMinute) % 60);
223 return static_cast<int>((get_Ticks() / TicksPerSecond) % 60);
229 return static_cast<int>((get_Ticks() / TicksPerMillisecond) % 1000);
235 return static_cast<int64_t
>(m_data & TicksMask);
384 return (t1 < t2 ? -1 : (t2 < t1 ? 1 : 0));
626 return Subtract(value);
634 return *
this = Add(value);
642 return *
this = Subtract(value);
650 return Subtract(value);
656 return *static_holder<ThisTypeInfo>();
659 constexpr bool IsNull()
const {
return false; }
660 constexpr bool operator==(std::nullptr_t)
const {
return false; }
661 constexpr bool operator!=(std::nullptr_t)
const {
return true; }
662 constexpr bool operator<(std::nullptr_t)
const {
return false; }
663 constexpr bool operator<=(std::nullptr_t)
const {
return false; }
664 constexpr bool operator>(std::nullptr_t)
const {
return false; }
665 constexpr bool operator>=(std::nullptr_t)
const {
return false; }
673 static constexpr uint64_t TicksMask = 0x3FFFFFFFFFFFFFFF;
674 static constexpr uint64_t FlagsMask = 0xC000000000000000;
677 constexpr uint64_t Flags()
const {
return m_data & FlagsMask; }
679 struct InternalConstructorTag {};
680 static constexpr InternalConstructorTag InternalConstructor{};
682 constexpr DateTime(uint64_t data, InternalConstructorTag) : m_data(data) {}
685 struct ThisTypeInfo : TypeInfoPtr
689 : TypeInfoPtr(u
"System::DateTime")
693#if defined(_DEBUG) && defined(_MSC_VER)
696 static constexpr unsigned DaysTo1901 = 693960;
697 static constexpr unsigned DaysTo2100 = 766644;
698 static constexpr unsigned DaysTo10000 = 3652058;
699 static constexpr unsigned DaysPer4Years = 1461;
701 struct Date { uint64_t ticks : 62; };
702 struct Days { uint64_t ticks:62; };
703 struct HoursMinutesSeconds { uint64_t ticks:62; };
704 struct Fraction { uint64_t ticks:62; };
705 struct TimeOfDay { uint64_t data; };
719template<>
struct IsBoxable<DateTime> : std::true_type {};
756 using result_type = std::size_t;
760 result_type operator()(
const argument_type& value)
const
762 return static_cast<result_type
>(value.GetHashCode());
Represents a specific date and time value on the time continuum. This type should be allocated on sta...
Definition: date_time.h:50
String ToString(const SharedPtr< Globalization::CultureInfo > &culture) const
String ToString(const String &format, const SharedPtr< Globalization::DateTimeFormatInfo > &dtfi) const
constexpr bool operator==(DateTime other) const
Determines if the current object and the specified DateTime object represent the same date and time v...
Definition: date_time.h:568
constexpr bool IsNull() const
Definition: date_time.h:659
static bool TryParse(const String &s, DateTime &result)
Converts the specified string representation of a date and time value to the equivalent DateTime obje...
constexpr bool operator>(DateTime other) const
Determines if the current object represents the date and time value that is later than the value repr...
Definition: date_time.h:600
String ToString(std::nullptr_t) const
Definition: date_time.h:431
String ToShortDateString() const
Returns a string that contains the short date string representation of the current object.
DateTime AddTicks(int64_t value) const
Returns a new instance of the DateTime class representing the date and time value which is the sum of...
static DateTime ParseExact(const String &s, const String &format, const SharedPtr< IFormatProvider > &provider, Globalization::DateTimeStyles styles=Globalization::DateTimeStyles::None)
Converts the specified string representation of a date and time value to the equivalent DateTime obje...
static const DateTime MaxValue
An instance of DateTime class that represents the maximal possible date and time value.
Definition: date_time.h:75
static bool TryParseExact(const String &s, const String &format, const SharedPtr< Globalization::CultureInfo > &culture, Globalization::DateTimeStyles styles, DateTime &result)
String ToString(const String &format, const SharedPtr< IFormatProvider > &provider) const
Returns a string representation of the date and time value represented by the current object using th...
String ToString(const String &format, const SharedPtr< Globalization::CultureInfo > &culture) const
int get_DayOfYear() const
Returns the ordinal number of the day in the year represented by the current object.
DateTime AddMinutes(double value) const
Returns a new instance of the DateTime class representing the date and time value which is the sum of...
int get_Day() const
Returns the ordinal number of the day in the month represented by the current object.
constexpr int64_t get_Ticks() const
Returns a number of 100-nanosecond intervals passed since 0:00:00 UTC, January 1, 0001,...
Definition: date_time.h:233
int64_t ToBinary() const
Serializes the current object.
double ToOADate() const
Returns the date and time value represented by the current object as OLE Automation Date.
static bool TryParseExact(const String &s, const String &format, const SharedPtr< IFormatProvider > &provider, Globalization::DateTimeStyles styles, DateTime &result)
Converts the specified string representation of a date and time value to the equivalent DateTime obje...
DateTime(int year, int month, int day, int hour, int minute, int second, int millisecond, DateTimeKind kind=DateTimeKind::Unspecified)
Constructs an instance that represents a date and time value specified as a particular year,...
static constexpr int Compare(DateTime t1, DateTime t2)
Compares two values represented by the specified instances of DateTime class and returns the value in...
Definition: date_time.h:382
constexpr DateTime()
Constructs an instance that represents the smallest possible date and time value equal to MinValue.
Definition: date_time.h:81
constexpr int get_Hour() const
Returns the hour component of the date and time value represented by the current object.
Definition: date_time.h:209
ArrayPtr< String > GetDateTimeFormats(const SharedPtr< IFormatProvider > &provider) const
Returns array of strings where each element is the string representation of the current object format...
String ToString(const String &format, std::nullptr_t) const
Definition: date_time.h:441
constexpr int get_Second() const
Returns the second component of the date and time value represented by the current object.
Definition: date_time.h:221
static DateTime ParseExact(const String &s, const ArrayPtr< String > &formats, const SharedPtr< Globalization::DateTimeFormatInfo > &dtfi, Globalization::DateTimeStyles styles)
DateTime(int year, int month, int day)
Constructs an instance that represents a date and time value specified as a particular year,...
static DateTime Parse(const String &s, const SharedPtr< Globalization::CultureInfo > &culture, Globalization::DateTimeStyles styles=Globalization::DateTimeStyles::None)
constexpr bool operator<(DateTime other) const
Determines if the current object represents the date and time value that is earlier than the value re...
Definition: date_time.h:584
static DateTime Parse(const String &s, std::nullptr_t, Globalization::DateTimeStyles styles=Globalization::DateTimeStyles::None)
static DateTime Parse(const String &s)
Converts the specified string representation of a date and time value to the equivalent DateTime obje...
String ToLongDateString() const
Returns a string that contains the long date string representation of the current object.
DateTime AddMonths(int value) const
Returns a new instance of the DateTime class representing the date and time value which is the sum of...
static DateTime ParseExact(const String &s, const String &format, const SharedPtr< Globalization::DateTimeFormatInfo > &dtfi, Globalization::DateTimeStyles styles=Globalization::DateTimeStyles::None)
DateTime & operator-=(TimeSpan value)
Sets the current object to the date and time value that is the result of subtraction of the specified...
Definition: date_time.h:640
constexpr TimeSpan operator-(DateTime value) const
Returns an instance of TimeSpan class that represents the time interval between the date and time val...
Definition: date_time.h:648
constexpr int get_Minute() const
Returns the minute component of the date and time value represented by the current object.
Definition: date_time.h:215
DateTime operator-(TimeSpan value) const
Returns a new instance of the DateTime class representing the date and time value which is the result...
Definition: date_time.h:624
static bool TryParseExact(const String &s, const ArrayPtr< String > &formats, const SharedPtr< Globalization::DateTimeFormatInfo > &dtfi, Globalization::DateTimeStyles styles, DateTime &result)
bool IsDaylightSavingTime() const
Determines if the date and time value represented by the current object falls in the range of dayligh...
static bool TryParse(const String &s, const SharedPtr< Globalization::DateTimeFormatInfo > &dtfi, Globalization::DateTimeStyles styles, DateTime &result)
DateTime ToLocalTime() const
Returns a new instance of DateTime class that represents the date and time value represented by the c...
DateTime(int64_t ticks, DateTimeKind kind, bool is_ambiguous_local_dst)
Construct an instance that represents a date and time value specified as a number of ticks....
constexpr bool operator>=(DateTime other) const
Determines if the current object represents the date and time value that is later than or the same as...
Definition: date_time.h:608
static DateTime FromOADate(double date)
Returns an instance of DateTime class representing the date and time value equivalent to the specifie...
String ToLongTimeString() const
Returns a string that contains the long time string representation of the current object.
constexpr TimeSpan get_TimeOfDay() const
Returns the value that represents the time interval from the beginning of the day represented by the ...
Definition: date_time.h:188
String ToShortTimeString() const
Returns a string that contains the short time string representation of the current object.
ArrayPtr< String > GetDateTimeFormats(char_t format, const SharedPtr< IFormatProvider > &provider) const
Returns array of strings where each element is the string representation of the current object format...
DateTime AddMilliseconds(double value) const
Returns a new instance of the DateTime class representing the date and time value which is the sum of...
DateTime AddYears(int value) const
Returns a new instance of the DateTime class representing the date and time value equal to that repre...
static DateTime FromFileTimeUtc(int64_t file_time)
Converts the specified File time to an instance of DateTime class representing the same date and time...
constexpr bool operator>(std::nullptr_t) const
Definition: date_time.h:664
static DateTime Parse(const String &s, const SharedPtr< IFormatProvider > &provider, Globalization::DateTimeStyles styles=Globalization::DateTimeStyles::None)
Converts the specified string representation of a date and time value to the equivalent DateTime obje...
constexpr bool operator==(std::nullptr_t) const
Definition: date_time.h:660
DateTime(int64_t ticks, DateTimeKind kind=DateTimeKind::Unspecified)
Construct an instance that represents a date and time value specified as a number of ticks.
constexpr int get_Millisecond() const
Returns the millisecond component of the date and time value represented by the current object.
Definition: date_time.h:227
DateTime AddHours(double value) const
Returns a new instance of the DateTime class representing the date and time value which is the sum of...
static DateTime get_Today()
Returns an instance of DateTime class that represents the current date with each component of time po...
constexpr bool operator<(std::nullptr_t) const
Definition: date_time.h:662
DateTime(int year, int month, int day, const SharedPtr< Globalization::Calendar > &calendar)
Constructs an instance that represents a date and time value specified as a particular year,...
DateTime Add(TimeSpan value) const
Returns a new instance of DateTime class that represents a date and time value that results from addi...
static bool TryParseExact(const String &s, const ArrayPtr< String > &formats, std::nullptr_t, Globalization::DateTimeStyles styles, DateTime &result)
constexpr int CompareTo(DateTime value) const
Compares two date and time values represented by the current object and the specified instance of Dat...
Definition: date_time.h:390
static DateTime get_UtcNow()
Returns an instance of DateTime class that represents the current time as UTC.
static DateTime ParseExact(const String &s, const String &format, const SharedPtr< Globalization::CultureInfo > &culture, Globalization::DateTimeStyles styles=Globalization::DateTimeStyles::None)
static bool TryParse(const String &s, const SharedPtr< Globalization::CultureInfo > &culture, Globalization::DateTimeStyles styles, DateTime &result)
void GetDateComponents(int &year, int &month, int &day) const
Gets date parts. FOR INTERNAL USE.
static bool TryParseExact(const String &s, const String &format, std::nullptr_t, Globalization::DateTimeStyles styles, DateTime &result)
constexpr bool operator!=(std::nullptr_t) const
Definition: date_time.h:661
ArrayPtr< String > GetDateTimeFormats(char_t format) const
Returns array of strings where each element is the string representation of the current object format...
static const DateTime UnixEpoch
An instance of DateTime class that represents the Unix epoch start (1970.01.01 00:00:00).
Definition: date_time.h:78
static bool TryParseExact(const String &s, const ArrayPtr< String > &formats, const SharedPtr< IFormatProvider > &provider, Globalization::DateTimeStyles styles, DateTime &result)
Converts the specified string representation of a date and time value to the equivalent DateTime obje...
DateTime & operator=(const DateTime &dt)=default
Assigns the value represented by the specified DateTime instance to the current object.
static DateTime get_Now()
Returns an instance of DateTime class that represents the current time as local time.
String ToString(const SharedPtr< Globalization::DateTimeFormatInfo > &dtfi) const
static bool TryParse(const String &s, const SharedPtr< IFormatProvider > &provider, Globalization::DateTimeStyles styles, DateTime &result)
Converts the specified string representation of a date and time value to the equivalent DateTime obje...
String ToString() const
Returns the string representation of the date and time value represented by the current object using ...
static DateTime ParseExact(const String &s, const String &format, std::nullptr_t, Globalization::DateTimeStyles styles=Globalization::DateTimeStyles::None)
static bool IsLeapYear(int year)
Determines of the specified year is a leap year.
DateTime(int year, int month, int day, int hour, int minute, int second)
Constructs an instance that represents a date and time value specified as a particular year,...
DateTime(int year, int month, int day, int hour, int minute, int second, int millisecond, const SharedPtr< Globalization::Calendar > &calendar, DateTimeKind kind=DateTimeKind::Unspecified)
Constructs an instance that represents a date and time value specified as a particular year,...
static DateTime Parse(const String &s, const SharedPtr< Globalization::DateTimeFormatInfo > &dtfi, Globalization::DateTimeStyles styles=Globalization::DateTimeStyles::None)
static bool TryParseExact(const String &s, const ArrayPtr< String > &formats, const SharedPtr< Globalization::CultureInfo > &culture, Globalization::DateTimeStyles styles, DateTime &result)
constexpr DayOfWeek get_DayOfWeek() const
Returns a value representing a day of week that is represented by the current object.
Definition: date_time.h:176
static const TypeInfo & Type()
Returns a TypeInfo object that contains information about this class.
Definition: date_time.h:654
static DateTime ParseExact(const String &s, const ArrayPtr< String > &formats, const SharedPtr< IFormatProvider > &provider, Globalization::DateTimeStyles styles)
Converts the specified string representation of a date and time value to the equivalent DateTime obje...
static DateTime FromUnixTime(time_t value)
Converts the specified Unix time value to an instance of DateTime class. FOR INTERNAL USE.
int64_t ToFileTime() const
Returns a value that represents the date and time value represented by the current object as File tim...
int get_Month() const
Returns the ordinal number of the month in the year represented by the current object.
constexpr bool operator<=(std::nullptr_t) const
Definition: date_time.h:663
static constexpr bool Equals(DateTime t1, DateTime t2)
Determines if the specified instances of DateTime class represent the same date and time value.
Definition: date_time.h:399
String ToString(const SharedPtr< IFormatProvider > &provider) const
Returns a string representation of the date and time value represented by the current object using th...
ArrayPtr< String > GetDateTimeFormats() const
Returns array of strings where each element is the string representation of the current object format...
String ToString(const String &format) const
Returns a string representation of the date and time value represented by the current object using th...
int get_Year() const
Returns the year represented by the current object.
constexpr bool operator<=(DateTime other) const
Determines if the current object represents the date and time value that is earlier than or the same ...
Definition: date_time.h:592
DateTime Subtract(TimeSpan duration) const
Returns a new instance of the DateTime class representing the date and time value which is the result...
DateTime(int year, int month, int day, int hour, int minute, int second, DateTimeKind kind)
Constructs an instance that represents a date and time value specified as a particular year,...
constexpr bool operator>=(std::nullptr_t) const
Definition: date_time.h:665
DateTime AddDays(double value) const
Returns a new instance of the DateTime class representing the date and time value which is the sum of...
DateTime AddSeconds(double value) const
Returns a new instance of the DateTime class representing the date and time value which is the sum of...
static bool TryParse(const String &s, std::nullptr_t, Globalization::DateTimeStyles styles, DateTime &result)
static DateTime SpecifyKind(DateTime value, DateTimeKind kind)
Constructs a new DateTime object that represents the same number of ticks as the specified DateTime o...
Definition: date_time.h:373
DateTime(int year, int month, int day, int hour, int minute, int second, const SharedPtr< Globalization::Calendar > &calendar)
Constructs an instance that represents a date and time value specified as a particular year,...
time_t ToUnixTime() const
Returns a value that represents the date and time value represented by the current object as Unix tim...
int64_t ToFileTimeUtc() const
Converts the date and time value represented by the current object to File time UTC.
DateTime(const DateTime &dt)=default
Copy-constructs an instance.
static DateTime ParseExact(const String &s, const ArrayPtr< String > &formats, const SharedPtr< Globalization::CultureInfo > &culture, Globalization::DateTimeStyles styles)
DateTime & operator+=(TimeSpan value)
Sets the current object to the date and time value that is the sum of the value represented by the cu...
Definition: date_time.h:632
constexpr TimeSpan Subtract(DateTime value) const
Returns an instance of TimeSpan class representing the time interval between the date and time values...
Definition: date_time.h:300
static bool TryParseExact(const String &s, const String &format, const SharedPtr< Globalization::DateTimeFormatInfo > &dtfi, Globalization::DateTimeStyles styles, DateTime &result)
static const DateTime MinValue
An instance of DateTime class that represents the minimal possible date and time value.
Definition: date_time.h:72
static DateTime ParseExact(const String &s, const ArrayPtr< String > &formats, std::nullptr_t, Globalization::DateTimeStyles styles)
constexpr DateTime get_Date() const
Returns a new instance of DateTime class that represents the date portion of the date and time repres...
Definition: date_time.h:169
constexpr bool operator!=(DateTime other) const
Determines if the current object and the specified DateTime object represent distinct date and time v...
Definition: date_time.h:576
static int DaysInMonth(int year, int month)
Returns the number of days in the specified month of the specified year.
DateTime operator+(TimeSpan value) const
Returns a new instance of DateTime class that represents the date and time value that is the sum of t...
Definition: date_time.h:616
DateTime ToUniversalTime() const
Returns a new instance of DateTime class that represents the date and time value represented by the c...
static DateTime FromBinary(int64_t value)
Deserializes the date time value from the specified unsigned 64-bit integer and sets the new instance...
int GetHashCode() const
Returns a hash code for the current object.
static DateTime FromFileTime(int64_t value)
Converts the specified File time to an instance of DateTime class representing the same date and time...
constexpr DateTimeKind get_Kind() const
Returns the value representing if the date and time represented by the current object is a local or U...
Definition: date_time.h:182
constexpr bool Equals(DateTime other) const
Determines if the specified instance of DateTime class represent the same date and time value as the ...
Definition: date_time.h:407
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
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.
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
DateTimeKind
Enumeration values of which represent the kinds of date and time.
Definition: date_time_kind.h:10
@ Unspecified
Unspecified kind.
@ DateTime
A type representing a date and time value.
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