|
DotNetDupe 4.0.6
C++17/20 Implementation of the .NET Base Class Library (BCL)
|
Represents an instant in time, typically expressed as a date and time of day. More...
#include <DateTime.h>
Public Member Functions | |
| DateTime () | |
| Initializes a new instance of DateTime to 0 ticks (0001-01-01 00:00:00) with Unspecified kind. | |
| DateTime (int year, int month, int day) | |
| Initializes a new instance of DateTime to specified year, month, and day. | |
| DateTime (int year, int month, int day, int hour, int minute, int second) | |
| Initializes a new instance of DateTime to specified date and time components. | |
| DateTime (int year, int month, int day, int hour, int minute, int second, DateTimeKind kind) | |
| Initializes a new instance of DateTime to specified date, time components, and kind. | |
| DateTime (int year, int month, int day, int hour, int minute, int second, int millisecond) | |
| Initializes a new instance of DateTime with millisecond precision. | |
| DateTime (int year, int month, int day, int hour, int minute, int second, int millisecond, DateTimeKind kind) | |
| Initializes a new instance of DateTime with millisecond precision and kind. | |
| DateTime (int64_t nTicks) | |
| Initializes a new instance of DateTime with a specified number of ticks. | |
| DateTime (int64_t nTicks, DateTimeKind kind) | |
| Initializes a new instance of DateTime with specified ticks and DateTimeKind. | |
| DateTime | Add (TimeSpan value) const |
| Returns a new DateTime that adds the value of the specified TimeSpan. | |
| DateTime | AddDays (double value) const |
| Returns a new DateTime that adds the specified number of days. | |
| DateTime | AddHours (double value) const |
| Returns a new DateTime that adds the specified number of hours. | |
| DateTime | AddMilliseconds (double value) const |
| Returns a new DateTime that adds the specified number of milliseconds. | |
| DateTime | AddMinutes (double value) const |
| Returns a new DateTime that adds the specified number of minutes. | |
| DateTime | AddMonths (int months) const |
| Returns a new DateTime that adds the specified number of months. | |
| DateTime | AddSeconds (double value) const |
| Returns a new DateTime that adds the specified number of seconds. | |
| DateTime | AddTicks (int64_t value) const |
| Returns a new DateTime that adds the specified number of ticks. | |
| DateTime | AddYears (int value) const |
| Returns a new DateTime that adds the specified number of years. | |
| DateTime | GetDate () const |
| Gets the date component of this instance with the time set to 00:00:00. | |
| int | GetDay () const |
| Gets the day of the month represented by this instance. | |
| int | GetDayOfWeek () const |
| Gets the day of the week represented by this instance. | |
| int | GetDayOfYear () const |
| Gets the day of the year represented by this instance. | |
| int | GetHour () const |
| Gets the hour component of the date represented by this instance. | |
| DateTimeKind | GetKind () const |
| Gets a value that indicates whether the time is local, UTC, or neither. | |
| int | GetMillisecond () const |
| Gets the milliseconds component of the date represented by this instance. | |
| int | GetMinute () const |
| Gets the minute component of the date represented by this instance. | |
| int | GetMonth () const |
| Gets the month component of the date represented by this instance. | |
| int | GetSecond () const |
| Gets the seconds component of the date represented by this instance. | |
| int64_t | GetTicks () const |
| Gets the number of ticks that represent the date and time of this instance. | |
| TimeSpan | GetTimeOfDay () const |
| Gets the time of day for this instance. | |
| int | GetYear () const |
| Gets the year component of the date represented by this instance. | |
| bool | operator!= (const DateTime &other) const |
| DateTime | operator+ (const TimeSpan &t) const |
| Adds a TimeSpan to this instance. | |
| TimeSpan | operator- (const DateTime &other) const |
| Subtracts a DateTime from this instance to calculate the elapsed TimeSpan. | |
| DateTime | operator- (const TimeSpan &t) const |
| Subtracts a TimeSpan from this instance. | |
| bool | operator< (const DateTime &other) const |
| bool | operator<= (const DateTime &other) const |
| bool | operator== (const DateTime &other) const |
| bool | operator> (const DateTime &other) const |
| bool | operator>= (const DateTime &other) const |
| DateTime | ToLocalTime () const |
| Converts the value of the current DateTime object to local time. | |
| String | ToString () const |
| Converts the value of the current DateTime object to its equivalent string representation. | |
| String | ToString (const String &sFormat) const |
| Converts the value of the current DateTime object to its equivalent string representation using format. | |
| DateTime | ToUniversalTime () const |
| Converts the value of the current DateTime object to Coordinated Universal Time (UTC). | |
| Public Member Functions inherited from DotNetDupe::System::Object | |
| virtual | ~Object ()=default |
| Virtual destructor ensuring polymorphic cleanup. | |
| virtual bool | Equals (const Object &obj) const |
| Determines whether the specified Object is equal to the current Object. | |
| virtual int | GetHashCode () const |
| Serves as the default hash function. | |
| bool | operator== (const Object &obj) const |
| Determines reference equality between two objects. | |
| char * | ToStringA () const |
| Returns narrow-character string representation. | |
| wchar_t * | ToStringW () const |
| Returns wide-character string representation. | |
Static Public Member Functions | |
| static int | DaysInMonth (int year, int month) |
| Returns the number of days in the specified month and year. | |
| static bool | IsLeapYear (int year) |
| Returns an indication whether the specified year is a leap year. | |
| static DateTime | Now () |
| Gets a DateTime object set to the current date and time on this computer, expressed as local time. | |
| static DateTime | Parse (const String &s) |
| Converts the string representation of a date and time to its DateTime equivalent. | |
| static DateTime | ParseExact (const String &s, const String &format) |
| Converts the string representation of a date and time to its DateTime equivalent using specified format. | |
| static DateTime | Today () |
| Gets the current date with the time component set to 00:00:00. | |
| static bool | TryParse (const String &s, DateTime &result) |
| Converts the string representation of a date and time to its DateTime equivalent and returns success flag. | |
| static bool | TryParseExact (const String &s, const String &format, DateTime &result) |
| Converts the string representation of a date and time to its DateTime equivalent using format and returns success flag. | |
| static DateTime | UtcNow () |
| Gets a DateTime object set to the current date and time on this computer, expressed as UTC. | |
| Static Public Member Functions inherited from DotNetDupe::System::Object | |
| static bool | Equals (const Object &obj1, const Object &obj2) |
| Static helper determining whether two object instances are equal. | |
Represents an instant in time, typically expressed as a date and time of day.
Definition at line 31 of file DateTime.h.
|
inline |
Initializes a new instance of DateTime to 0 ticks (0001-01-01 00:00:00) with Unspecified kind.
Definition at line 34 of file DateTime.h.
References DOTNETDUPE_API, and DotNetDupe::System::Unspecified.
Referenced by Add(), AddDays(), AddHours(), AddMilliseconds(), AddMinutes(), AddMonths(), AddSeconds(), AddTicks(), AddYears(), GetDate(), Now(), operator!=(), operator+(), operator-(), operator-(), operator<(), operator<=(), operator==(), operator>(), operator>=(), Parse(), DotNetDupe::System::ParseDateTimeStr(), ParseExact(), Today(), ToLocalTime(), ToUniversalTime(), TryParse(), TryParseExact(), and UtcNow().
|
inline |
Initializes a new instance of DateTime with a specified number of ticks.
| nTicks | A date and time expressed in the number of 100-nanosecond units. |
Definition at line 38 of file DateTime.h.
References DOTNETDUPE_API, and DotNetDupe::System::Unspecified.
|
inline |
Initializes a new instance of DateTime with specified ticks and DateTimeKind.
| nTicks | A date and time expressed in ticks. |
| kind | One of the enumeration values that indicates whether ticks specifies local time, UTC, or neither. |
Definition at line 43 of file DateTime.h.
References DOTNETDUPE_API.
| DotNetDupe::System::DateTime::DateTime | ( | int | year, |
| int | month, | ||
| int | day ) |
Initializes a new instance of DateTime to specified year, month, and day.
| year | The year (1 through 9999). |
| month | The month (1 through 12). |
| day | The day (1 through the number of days in month). |
Definition at line 82 of file DateTime.cpp.
References DotNetDupe::System::DateToTicks(), and DotNetDupe::System::Unspecified.
| DotNetDupe::System::DateTime::DateTime | ( | int | year, |
| int | month, | ||
| int | day, | ||
| int | hour, | ||
| int | minute, | ||
| int | second ) |
Initializes a new instance of DateTime to specified date and time components.
| year | The year (1 through 9999). |
| month | The month (1 through 12). |
| day | The day (1 through the number of days in month). |
| hour | The hours (0 through 23). |
| minute | The minutes (0 through 59). |
| second | The seconds (0 through 59). |
Definition at line 85 of file DateTime.cpp.
References DotNetDupe::System::DateToTicks(), DotNetDupe::System::TimeToTicks(), and DotNetDupe::System::Unspecified.
| DotNetDupe::System::DateTime::DateTime | ( | int | year, |
| int | month, | ||
| int | day, | ||
| int | hour, | ||
| int | minute, | ||
| int | second, | ||
| DateTimeKind | kind ) |
Initializes a new instance of DateTime to specified date, time components, and kind.
Definition at line 88 of file DateTime.cpp.
References DotNetDupe::System::DateToTicks(), and DotNetDupe::System::TimeToTicks().
| DotNetDupe::System::DateTime::DateTime | ( | int | year, |
| int | month, | ||
| int | day, | ||
| int | hour, | ||
| int | minute, | ||
| int | second, | ||
| int | millisecond ) |
Initializes a new instance of DateTime with millisecond precision.
Guard: Validate millisecond range.
Definition at line 91 of file DateTime.cpp.
References DotNetDupe::System::ArgumentOutOfRangeException::ArgumentOutOfRangeException(), DotNetDupe::System::DateToTicks(), DotNetDupe::System::TicksPerMillisecond, DotNetDupe::System::TimeToTicks(), and DotNetDupe::System::Unspecified.
| DotNetDupe::System::DateTime::DateTime | ( | int | year, |
| int | month, | ||
| int | day, | ||
| int | hour, | ||
| int | minute, | ||
| int | second, | ||
| int | millisecond, | ||
| DateTimeKind | kind ) |
Initializes a new instance of DateTime with millisecond precision and kind.
Guard: Validate millisecond range.
Definition at line 99 of file DateTime.cpp.
References DotNetDupe::System::ArgumentOutOfRangeException::ArgumentOutOfRangeException(), DotNetDupe::System::DateToTicks(), DotNetDupe::System::TicksPerMillisecond, and DotNetDupe::System::TimeToTicks().
Returns a new DateTime that adds the value of the specified TimeSpan.
Add duration ticks to date.
Definition at line 172 of file DateTime.cpp.
References DateTime(), AddTicks(), and DotNetDupe::System::TimeSpan::GetTicks().
| DateTime DotNetDupe::System::DateTime::AddDays | ( | double | value | ) | const |
Returns a new DateTime that adds the specified number of days.
Scale days to milliseconds and add.
Definition at line 177 of file DateTime.cpp.
References DateTime(), and AddMilliseconds().
| DateTime DotNetDupe::System::DateTime::AddHours | ( | double | value | ) | const |
Returns a new DateTime that adds the specified number of hours.
Scale hours to milliseconds and add.
Definition at line 182 of file DateTime.cpp.
References DateTime(), and AddMilliseconds().
| DateTime DotNetDupe::System::DateTime::AddMilliseconds | ( | double | value | ) | const |
Returns a new DateTime that adds the specified number of milliseconds.
Convert milliseconds to nearest integer ticks with rounding.
Definition at line 187 of file DateTime.cpp.
References DateTime(), AddTicks(), and DotNetDupe::System::TicksPerMillisecond.
Referenced by AddDays(), AddHours(), AddMinutes(), and AddSeconds().
| DateTime DotNetDupe::System::DateTime::AddMinutes | ( | double | value | ) | const |
Returns a new DateTime that adds the specified number of minutes.
Scale minutes to milliseconds and add.
Definition at line 193 of file DateTime.cpp.
References DateTime(), and AddMilliseconds().
| DateTime DotNetDupe::System::DateTime::AddMonths | ( | int | months | ) | const |
Returns a new DateTime that adds the specified number of months.
Guard: Validate month offset limit.
Decompose date and adjust month and year.
Validate year range and clamp day of month.
Reconstruct DateTime preserving time of day.
Definition at line 198 of file DateTime.cpp.
References DotNetDupe::System::ArgumentOutOfRangeException::ArgumentOutOfRangeException(), DateTime(), DotNetDupe::System::DateToTicks(), DaysInMonth(), DotNetDupe::System::GetDatePart(), and DotNetDupe::System::TicksPerDay.
Referenced by AddYears().
| DateTime DotNetDupe::System::DateTime::AddSeconds | ( | double | value | ) | const |
Returns a new DateTime that adds the specified number of seconds.
Scale seconds to milliseconds and add.
Definition at line 217 of file DateTime.cpp.
References DateTime(), and AddMilliseconds().
| DateTime DotNetDupe::System::DateTime::AddTicks | ( | int64_t | value | ) | const |
Returns a new DateTime that adds the specified number of ticks.
Calculate new ticks and enforce minimum/maximum boundaries.
Definition at line 222 of file DateTime.cpp.
References DotNetDupe::System::ArgumentOutOfRangeException::ArgumentOutOfRangeException(), DateTime(), and DotNetDupe::System::MaxTicks.
Referenced by Add(), and AddMilliseconds().
| DateTime DotNetDupe::System::DateTime::AddYears | ( | int | value | ) | const |
Returns a new DateTime that adds the specified number of years.
Guard: Validate year boundary.
Add months corresponding to full years.
Definition at line 232 of file DateTime.cpp.
References DotNetDupe::System::ArgumentOutOfRangeException::ArgumentOutOfRangeException(), DateTime(), and AddMonths().
|
static |
Returns the number of days in the specified month and year.
Guard: Validate month parameter.
Look up day count using leap-year aware month table.
Definition at line 333 of file DateTime.cpp.
References DotNetDupe::System::ArgumentOutOfRangeException::ArgumentOutOfRangeException(), DotNetDupe::System::DaysToMonth365, DotNetDupe::System::DaysToMonth366, and IsLeapYear().
Referenced by AddMonths().
| DateTime DotNetDupe::System::DateTime::GetDate | ( | ) | const |
Gets the date component of this instance with the time set to 00:00:00.
Strip time of day portion by rounding down to day ticks.
Definition at line 162 of file DateTime.cpp.
References DateTime(), and DotNetDupe::System::TicksPerDay.
Referenced by Today().
| int DotNetDupe::System::DateTime::GetDay | ( | ) | const |
Gets the day of the month represented by this instance.
Decompose ticks to calendar date.
Definition at line 121 of file DateTime.cpp.
References DotNetDupe::System::GetDatePart().
| int DotNetDupe::System::DateTime::GetDayOfWeek | ( | ) | const |
Gets the day of the week represented by this instance.
Compute 0-indexed day of week where Sunday is 0.
Definition at line 157 of file DateTime.cpp.
References DotNetDupe::System::TicksPerDay.
| int DotNetDupe::System::DateTime::GetDayOfYear | ( | ) | const |
Gets the day of the year represented by this instance.
Decompose ticks to calendar date and add day offset.
Definition at line 148 of file DateTime.cpp.
References DotNetDupe::System::DaysToMonth365, DotNetDupe::System::DaysToMonth366, DotNetDupe::System::GetDatePart(), and IsLeapYear().
| int DotNetDupe::System::DateTime::GetHour | ( | ) | const |
Gets the hour component of the date represented by this instance.
Calculate hour from ticks quotient modulo 24.
Definition at line 128 of file DateTime.cpp.
References DotNetDupe::System::TicksPerHour.
Referenced by ToString().
|
inline |
Gets a value that indicates whether the time is local, UTC, or neither.
Definition at line 75 of file DateTime.h.
| int DotNetDupe::System::DateTime::GetMillisecond | ( | ) | const |
Gets the milliseconds component of the date represented by this instance.
Calculate millisecond from ticks quotient modulo 1000.
Definition at line 143 of file DateTime.cpp.
References DotNetDupe::System::TicksPerMillisecond.
| int DotNetDupe::System::DateTime::GetMinute | ( | ) | const |
Gets the minute component of the date represented by this instance.
Calculate minute from ticks quotient modulo 60.
Definition at line 133 of file DateTime.cpp.
References DotNetDupe::System::TicksPerMinute.
Referenced by ToString().
| int DotNetDupe::System::DateTime::GetMonth | ( | ) | const |
Gets the month component of the date represented by this instance.
Decompose ticks to calendar date.
Definition at line 114 of file DateTime.cpp.
References DotNetDupe::System::GetDatePart().
| int DotNetDupe::System::DateTime::GetSecond | ( | ) | const |
Gets the seconds component of the date represented by this instance.
Calculate second from ticks quotient modulo 60.
Definition at line 138 of file DateTime.cpp.
References DotNetDupe::System::TicksPerSecond.
Referenced by ToString().
|
inline |
Gets the number of ticks that represent the date and time of this instance.
Definition at line 71 of file DateTime.h.
| TimeSpan DotNetDupe::System::DateTime::GetTimeOfDay | ( | ) | const |
Gets the time of day for this instance.
Extract time portion as TimeSpan modulo one day.
Definition at line 167 of file DateTime.cpp.
References DotNetDupe::System::TimeSpan::TimeSpan(), and DotNetDupe::System::TicksPerDay.
| int DotNetDupe::System::DateTime::GetYear | ( | ) | const |
Gets the year component of the date represented by this instance.
Decompose ticks to calendar date.
Definition at line 107 of file DateTime.cpp.
References DotNetDupe::System::GetDatePart().
|
static |
Returns an indication whether the specified year is a leap year.
Guard: Validate Gregorian year boundaries.
Gregorian leap year rule: divisible by 4, not divisible by 100 unless divisible by 400.
Definition at line 344 of file DateTime.cpp.
References DotNetDupe::System::ArgumentOutOfRangeException::ArgumentOutOfRangeException().
Referenced by DotNetDupe::System::DateToTicks(), DaysInMonth(), DotNetDupe::System::GetDatePart(), and GetDayOfYear().
|
static |
Gets a DateTime object set to the current date and time on this computer, expressed as local time.
Obtain UTC time and convert to local time zone.
Definition at line 242 of file DateTime.cpp.
References DateTime(), ToLocalTime(), and UtcNow().
Referenced by Today().
|
inline |
Definition at line 207 of file DateTime.h.
References DateTime().
Adds a TimeSpan to this instance.
Definition at line 197 of file DateTime.h.
References DateTime(), and DotNetDupe::System::TimeSpan::GetTicks().
Subtracts a DateTime from this instance to calculate the elapsed TimeSpan.
Definition at line 192 of file DateTime.h.
References DateTime(), and DotNetDupe::System::TimeSpan::TimeSpan().
Subtracts a TimeSpan from this instance.
Definition at line 202 of file DateTime.h.
References DateTime(), and DotNetDupe::System::TimeSpan::GetTicks().
|
inline |
Definition at line 208 of file DateTime.h.
References DateTime().
|
inline |
Definition at line 209 of file DateTime.h.
References DateTime().
|
inline |
Definition at line 206 of file DateTime.h.
References DateTime().
|
inline |
Definition at line 210 of file DateTime.h.
References DateTime().
|
inline |
Definition at line 211 of file DateTime.h.
References DateTime().
Converts the string representation of a date and time to its DateTime equivalent.
| s | A string that contains a date and time to convert. |
| FormatException | s does not contain a valid string representation of a date and time. |
Attempt parse and throw FormatException on failure.
Definition at line 410 of file DateTime.cpp.
References DateTime(), DotNetDupe::System::FormatException::FormatException(), and TryParse().
|
static |
Converts the string representation of a date and time to its DateTime equivalent using specified format.
| FormatException | s does not match format. |
Attempt exact parse and throw FormatException on failure.
Definition at line 400 of file DateTime.cpp.
References DateTime(), DotNetDupe::System::FormatException::FormatException(), and TryParseExact().
|
static |
Gets the current date with the time component set to 00:00:00.
Obtain current local date with midnight time component.
Definition at line 259 of file DateTime.cpp.
References DateTime(), GetDate(), and Now().
| DateTime DotNetDupe::System::DateTime::ToLocalTime | ( | ) | const |
Converts the value of the current DateTime object to local time.
Guard: Return directly if already local time.
Convert ticks relative to Unix epoch to local calendar.
Definition at line 297 of file DateTime.cpp.
References DateTime(), DotNetDupe::System::ConvertToLocalTm(), DotNetDupe::System::Local, DotNetDupe::System::TicksPerSecond, DotNetDupe::System::TmToTicks(), and DotNetDupe::System::UnixEpochTicks.
Referenced by Now().
| String DotNetDupe::System::DateTime::ToString | ( | ) | const |
Converts the value of the current DateTime object to its equivalent string representation.
Format using default ISO 8601 extended pattern.
Definition at line 317 of file DateTime.cpp.
References ToString().
Referenced by ToString().
Converts the value of the current DateTime object to its equivalent string representation using format.
Format date components using standard ISO format.
Definition at line 322 of file DateTime.cpp.
References DotNetDupe::System::String::String(), DotNetDupe::System::GetDatePart(), GetHour(), GetMinute(), and GetSecond().
| DateTime DotNetDupe::System::DateTime::ToUniversalTime | ( | ) | const |
Converts the value of the current DateTime object to Coordinated Universal Time (UTC).
Guard: Return directly if already UTC.
Convert ticks relative to Unix epoch to UTC calendar.
Definition at line 307 of file DateTime.cpp.
References DateTime(), DotNetDupe::System::ConvertToUtcTm(), DotNetDupe::System::TicksPerSecond, DotNetDupe::System::TmToTicks(), DotNetDupe::System::UnixEpochTicks, and DotNetDupe::System::Utc.
Converts the string representation of a date and time to its DateTime equivalent and returns success flag.
Attempt parse against default ISO format.
Definition at line 395 of file DateTime.cpp.
References DateTime(), and DotNetDupe::System::ParseDateTimeStr().
Referenced by Parse().
|
static |
Converts the string representation of a date and time to its DateTime equivalent using format and returns success flag.
Attempt parse against exact format specification.
Definition at line 390 of file DateTime.cpp.
References DateTime(), and DotNetDupe::System::ParseDateTimeStr().
Referenced by ParseExact().
|
static |
Gets a DateTime object set to the current date and time on this computer, expressed as UTC.
Query high-resolution system clock.
Convert microseconds to 100-nanosecond ticks and offset by Unix epoch.
Definition at line 248 of file DateTime.cpp.
References DateTime(), DotNetDupe::System::UnixEpochTicks, and DotNetDupe::System::Utc.
Referenced by Now().