diff options
Diffstat (limited to 'src/System.Private.CoreLib/shared/System/DateTime.cs')
-rw-r--r-- | src/System.Private.CoreLib/shared/System/DateTime.cs | 241 |
1 files changed, 109 insertions, 132 deletions
diff --git a/src/System.Private.CoreLib/shared/System/DateTime.cs b/src/System.Private.CoreLib/shared/System/DateTime.cs index b5deefa94..5b76f6092 100644 --- a/src/System.Private.CoreLib/shared/System/DateTime.cs +++ b/src/System.Private.CoreLib/shared/System/DateTime.cs @@ -115,18 +115,18 @@ namespace System public static readonly DateTime MaxValue = new DateTime(MaxTicks, DateTimeKind.Unspecified); public static readonly DateTime UnixEpoch = new DateTime(UnixEpochTicks, DateTimeKind.Utc); - private const UInt64 TicksMask = 0x3FFFFFFFFFFFFFFF; - private const UInt64 FlagsMask = 0xC000000000000000; - private const UInt64 LocalMask = 0x8000000000000000; - private const Int64 TicksCeiling = 0x4000000000000000; - private const UInt64 KindUnspecified = 0x0000000000000000; - private const UInt64 KindUtc = 0x4000000000000000; - private const UInt64 KindLocal = 0x8000000000000000; - private const UInt64 KindLocalAmbiguousDst = 0xC000000000000000; - private const Int32 KindShift = 62; - - private const String TicksField = "ticks"; // Do not rename (binary serialization) - private const String DateDataField = "dateData"; // Do not rename (binary serialization) + private const ulong TicksMask = 0x3FFFFFFFFFFFFFFF; + private const ulong FlagsMask = 0xC000000000000000; + private const ulong LocalMask = 0x8000000000000000; + private const long TicksCeiling = 0x4000000000000000; + private const ulong KindUnspecified = 0x0000000000000000; + private const ulong KindUtc = 0x4000000000000000; + private const ulong KindLocal = 0x8000000000000000; + private const ulong KindLocalAmbiguousDst = 0xC000000000000000; + private const int KindShift = 62; + + private const string TicksField = "ticks"; // Do not rename (binary serialization) + private const string DateDataField = "dateData"; // Do not rename (binary serialization) // The data is stored as an unsigned 64-bit integer // Bits 01-62: The value of 100-nanosecond ticks where 0 represents 1/1/0001 12:00am, up until the value @@ -136,7 +136,7 @@ namespace System // savings time hour and it is in daylight savings time. This allows distinction of these // otherwise ambiguous local times and prevents data loss when round tripping from Local to // UTC time. - private readonly UInt64 _dateData; + private readonly ulong _dateData; // Constructs a DateTime from a tick count. The ticks // argument specifies the date as the number of 100-nanosecond intervals @@ -146,10 +146,10 @@ namespace System { if (ticks < MinTicks || ticks > MaxTicks) throw new ArgumentOutOfRangeException(nameof(ticks), SR.ArgumentOutOfRange_DateTimeBadTicks); - _dateData = (UInt64)ticks; + _dateData = (ulong)ticks; } - private DateTime(UInt64 dateData) + private DateTime(ulong dateData) { this._dateData = dateData; } @@ -164,17 +164,17 @@ namespace System { throw new ArgumentException(SR.Argument_InvalidDateTimeKind, nameof(kind)); } - _dateData = ((UInt64)ticks | ((UInt64)kind << KindShift)); + _dateData = ((ulong)ticks | ((ulong)kind << KindShift)); } - internal DateTime(long ticks, DateTimeKind kind, Boolean isAmbiguousDst) + internal DateTime(long ticks, DateTimeKind kind, bool isAmbiguousDst) { if (ticks < MinTicks || ticks > MaxTicks) { throw new ArgumentOutOfRangeException(nameof(ticks), SR.ArgumentOutOfRange_DateTimeBadTicks); } Debug.Assert(kind == DateTimeKind.Local, "Internal Constructor is for local times only"); - _dateData = ((UInt64)ticks | (isAmbiguousDst ? KindLocalAmbiguousDst : KindLocal)); + _dateData = ((ulong)ticks | (isAmbiguousDst ? KindLocalAmbiguousDst : KindLocal)); } // Constructs a DateTime from a given year, month, and day. The @@ -182,7 +182,7 @@ namespace System // public DateTime(int year, int month, int day) { - _dateData = (UInt64)DateToTicks(year, month, day); + _dateData = (ulong)DateToTicks(year, month, day); } // Constructs a DateTime from a given year, month, and day for @@ -199,7 +199,7 @@ namespace System // public DateTime(int year, int month, int day, int hour, int minute, int second) { - _dateData = (UInt64)(DateToTicks(year, month, day) + TimeToTicks(hour, minute, second)); + _dateData = (ulong)(DateToTicks(year, month, day) + TimeToTicks(hour, minute, second)); } public DateTime(int year, int month, int day, int hour, int minute, int second, DateTimeKind kind) @@ -208,8 +208,8 @@ namespace System { throw new ArgumentException(SR.Argument_InvalidDateTimeKind, nameof(kind)); } - Int64 ticks = DateToTicks(year, month, day) + TimeToTicks(hour, minute, second); - _dateData = ((UInt64)ticks | ((UInt64)kind << KindShift)); + long ticks = DateToTicks(year, month, day) + TimeToTicks(hour, minute, second); + _dateData = ((ulong)ticks | ((ulong)kind << KindShift)); } // Constructs a DateTime from a given year, month, day, hour, @@ -219,7 +219,7 @@ namespace System { if (calendar == null) throw new ArgumentNullException(nameof(calendar)); - _dateData = (UInt64)calendar.ToDateTime(year, month, day, hour, minute, second, 0).Ticks; + _dateData = (ulong)calendar.ToDateTime(year, month, day, hour, minute, second, 0).Ticks; } // Constructs a DateTime from a given year, month, day, hour, @@ -231,11 +231,11 @@ namespace System { throw new ArgumentOutOfRangeException(nameof(millisecond), SR.Format(SR.ArgumentOutOfRange_Range, 0, MillisPerSecond - 1)); } - Int64 ticks = DateToTicks(year, month, day) + TimeToTicks(hour, minute, second); + long ticks = DateToTicks(year, month, day) + TimeToTicks(hour, minute, second); ticks += millisecond * TicksPerMillisecond; if (ticks < MinTicks || ticks > MaxTicks) throw new ArgumentException(SR.Arg_DateTimeRange); - _dateData = (UInt64)ticks; + _dateData = (ulong)ticks; } public DateTime(int year, int month, int day, int hour, int minute, int second, int millisecond, DateTimeKind kind) @@ -248,11 +248,11 @@ namespace System { throw new ArgumentException(SR.Argument_InvalidDateTimeKind, nameof(kind)); } - Int64 ticks = DateToTicks(year, month, day) + TimeToTicks(hour, minute, second); + long ticks = DateToTicks(year, month, day) + TimeToTicks(hour, minute, second); ticks += millisecond * TicksPerMillisecond; if (ticks < MinTicks || ticks > MaxTicks) throw new ArgumentException(SR.Arg_DateTimeRange); - _dateData = ((UInt64)ticks | ((UInt64)kind << KindShift)); + _dateData = ((ulong)ticks | ((ulong)kind << KindShift)); } // Constructs a DateTime from a given year, month, day, hour, @@ -266,11 +266,11 @@ namespace System { throw new ArgumentOutOfRangeException(nameof(millisecond), SR.Format(SR.ArgumentOutOfRange_Range, 0, MillisPerSecond - 1)); } - Int64 ticks = calendar.ToDateTime(year, month, day, hour, minute, second, 0).Ticks; + long ticks = calendar.ToDateTime(year, month, day, hour, minute, second, 0).Ticks; ticks += millisecond * TicksPerMillisecond; if (ticks < MinTicks || ticks > MaxTicks) throw new ArgumentException(SR.Arg_DateTimeRange); - _dateData = (UInt64)ticks; + _dateData = (ulong)ticks; } public DateTime(int year, int month, int day, int hour, int minute, int second, int millisecond, Calendar calendar, DateTimeKind kind) @@ -285,11 +285,11 @@ namespace System { throw new ArgumentException(SR.Argument_InvalidDateTimeKind, nameof(kind)); } - Int64 ticks = calendar.ToDateTime(year, month, day, hour, minute, second, 0).Ticks; + long ticks = calendar.ToDateTime(year, month, day, hour, minute, second, 0).Ticks; ticks += millisecond * TicksPerMillisecond; if (ticks < MinTicks || ticks > MaxTicks) throw new ArgumentException(SR.Arg_DateTimeRange); - _dateData = ((UInt64)ticks | ((UInt64)kind << KindShift)); + _dateData = ((ulong)ticks | ((ulong)kind << KindShift)); } private DateTime(SerializationInfo info, StreamingContext context) @@ -297,10 +297,10 @@ namespace System if (info == null) throw new ArgumentNullException(nameof(info)); - Boolean foundTicks = false; - Boolean foundDateData = false; - Int64 serializedTicks = 0; - UInt64 serializedDateData = 0; + bool foundTicks = false; + bool foundDateData = false; + long serializedTicks = 0; + ulong serializedDateData = 0; // Get the data @@ -328,13 +328,13 @@ namespace System } else if (foundTicks) { - _dateData = (UInt64)serializedTicks; + _dateData = (ulong)serializedTicks; } else { throw new SerializationException(SR.Serialization_MissingDateTimeData); } - Int64 ticks = InternalTicks; + long ticks = InternalTicks; if (ticks < MinTicks || ticks > MaxTicks) { throw new SerializationException(SR.Serialization_DateTimeTicksOutOfRange); @@ -343,15 +343,15 @@ namespace System - internal Int64 InternalTicks + internal long InternalTicks { get { - return (Int64)(_dateData & TicksMask); + return (long)(_dateData & TicksMask); } } - private UInt64 InternalKind + private ulong InternalKind { get { @@ -459,7 +459,7 @@ namespace System } int days = DaysInMonth(y, m); if (d > days) d = days; - return new DateTime((UInt64)(DateToTicks(y, m, d) + InternalTicks % TicksPerDay) | InternalKind); + return new DateTime((ulong)(DateToTicks(y, m, d) + InternalTicks % TicksPerDay) | InternalKind); } // Returns the DateTime resulting from adding a fractional number of @@ -484,7 +484,7 @@ namespace System { throw new ArgumentOutOfRangeException(nameof(value), SR.ArgumentOutOfRange_DateArithmetic); } - return new DateTime((UInt64)(ticks + value) | InternalKind); + return new DateTime((ulong)(ticks + value) | InternalKind); } // Returns the DateTime resulting from adding the given number of @@ -511,8 +511,8 @@ namespace System // public static int Compare(DateTime t1, DateTime t2) { - Int64 ticks1 = t1.InternalTicks; - Int64 ticks2 = t2.InternalTicks; + long ticks1 = t1.InternalTicks; + long ticks2 = t2.InternalTicks; if (ticks1 > ticks2) return 1; if (ticks1 < ticks2) return -1; return 0; @@ -524,7 +524,7 @@ namespace System // occurs. Null is considered less than any instance. // // Returns a value less than zero if this object - public int CompareTo(Object value) + public int CompareTo(object value) { if (value == null) return 1; if (!(value is DateTime)) @@ -610,7 +610,7 @@ namespace System // is equal to the value of this DateTime. Returns false // otherwise. // - public override bool Equals(Object value) + public override bool Equals(object value) { if (value is DateTime) { @@ -633,15 +633,15 @@ namespace System return t1.InternalTicks == t2.InternalTicks; } - public static DateTime FromBinary(Int64 dateData) + public static DateTime FromBinary(long dateData) { - if ((dateData & (unchecked((Int64)LocalMask))) != 0) + if ((dateData & (unchecked((long)LocalMask))) != 0) { // Local times need to be adjusted as you move from one time zone to another, // just as they are when serializing in text. As such the format for local times // changes to store the ticks of the UTC time, but with flags that look like a // local date. - Int64 ticks = dateData & (unchecked((Int64)TicksMask)); + long ticks = dateData & (unchecked((long)TicksMask)); // Negative ticks are stored in the top part of the range and should be converted back into a negative number if (ticks > TicksCeiling - TicksPerDay) { @@ -649,8 +649,8 @@ namespace System } // Convert the ticks back to local. If the UTC ticks are out of range, we need to default to // the UTC offset from MinValue and MaxValue to be consistent with Parse. - Boolean isAmbiguousLocalDst = false; - Int64 offsetTicks; + bool isAmbiguousLocalDst = false; + long offsetTicks; if (ticks < MinTicks) { offsetTicks = TimeZoneInfo.GetLocalUtcOffset(DateTime.MinValue, TimeZoneInfoOptions.NoThrowOnInvalidTime).Ticks; @@ -664,7 +664,7 @@ namespace System // Because the ticks conversion between UTC and local is lossy, we need to capture whether the // time is in a repeated hour so that it can be passed to the DateTime constructor. DateTime utcDt = new DateTime(ticks, DateTimeKind.Utc); - Boolean isDaylightSavings = false; + bool isDaylightSavings = false; offsetTicks = TimeZoneInfo.GetUtcOffsetFromUtc(utcDt, TimeZoneInfo.Local, out isDaylightSavings, out isAmbiguousLocalDst).Ticks; } ticks += offsetTicks; @@ -688,12 +688,12 @@ namespace System // A version of ToBinary that uses the real representation and does not adjust local times. This is needed for // scenarios where the serialized data must maintain compatibility - internal static DateTime FromBinaryRaw(Int64 dateData) + internal static DateTime FromBinaryRaw(long dateData) { - Int64 ticks = dateData & (Int64)TicksMask; + long ticks = dateData & (long)TicksMask; if (ticks < MinTicks || ticks > MaxTicks) throw new ArgumentException(SR.Argument_DateTimeBadBinaryData, nameof(dateData)); - return new DateTime((UInt64)dateData); + return new DateTime((ulong)dateData); } // Creates a DateTime from a Windows filetime. A Windows filetime is @@ -736,7 +736,7 @@ namespace System info.AddValue(DateDataField, _dateData); } - public Boolean IsDaylightSavingTime() + public bool IsDaylightSavingTime() { if (Kind == DateTimeKind.Utc) { @@ -750,7 +750,7 @@ namespace System return new DateTime(value.InternalTicks, kind); } - public Int64 ToBinary() + public long ToBinary() { if (Kind == DateTimeKind.Local) { @@ -765,17 +765,17 @@ namespace System // end of the maximum range, and values just below minimum value are stored // at the end of the ticks area, just below 2^62. TimeSpan offset = TimeZoneInfo.GetLocalUtcOffset(this, TimeZoneInfoOptions.NoThrowOnInvalidTime); - Int64 ticks = Ticks; - Int64 storedTicks = ticks - offset.Ticks; + long ticks = Ticks; + long storedTicks = ticks - offset.Ticks; if (storedTicks < 0) { storedTicks = TicksCeiling + storedTicks; } - return storedTicks | (unchecked((Int64)LocalMask)); + return storedTicks | (unchecked((long)LocalMask)); } else { - return (Int64)_dateData; + return (long)_dateData; } } @@ -787,8 +787,8 @@ namespace System { get { - Int64 ticks = InternalTicks; - return new DateTime((UInt64)(ticks - ticks % TicksPerDay) | InternalKind); + long ticks = InternalTicks; + return new DateTime((ulong)(ticks - ticks % TicksPerDay) | InternalKind); } } @@ -796,7 +796,7 @@ namespace System // to compute the year, day-of-year, month, or day part. private int GetDatePart(int part) { - Int64 ticks = InternalTicks; + long ticks = InternalTicks; // n = number of days since 1/1/0001 int n = (int)(ticks / TicksPerDay); // y400 = number of whole 400-year periods since 1/1/0001 @@ -846,7 +846,7 @@ namespace System // are needed rather than redoing the computations for each. internal void GetDatePart(out int year, out int month, out int day) { - Int64 ticks = InternalTicks; + long ticks = InternalTicks; // n = number of days since 1/1/0001 int n = (int)(ticks / TicksPerDay); // y400 = number of whole 400-year periods since 1/1/0001 @@ -925,7 +925,7 @@ namespace System // public override int GetHashCode() { - Int64 ticks = InternalTicks; + long ticks = InternalTicks; return unchecked((int)ticks) ^ (int)(ticks >> 32); } @@ -940,7 +940,7 @@ namespace System } } - internal Boolean IsAmbiguousDaylightSavingTime() + internal bool IsAmbiguousDaylightSavingTime() { return (InternalKind == KindLocalAmbiguousDst); } @@ -1001,8 +1001,8 @@ namespace System get { DateTime utc = UtcNow; - Boolean isAmbiguousLocalDst = false; - Int64 offset = TimeZoneInfo.GetDateTimeNowUtcOffsetFromUtc(utc, out isAmbiguousLocalDst).Ticks; + bool isAmbiguousLocalDst = false; + long offset = TimeZoneInfo.GetDateTimeNowUtcOffsetFromUtc(utc, out isAmbiguousLocalDst).Ticks; long tick = utc.Ticks + offset; if (tick > DateTime.MaxTicks) { @@ -1089,7 +1089,7 @@ namespace System // date and optionally a time in a culture-specific or universal format. // Leading and trailing whitespace characters are allowed. // - public static DateTime Parse(String s) + public static DateTime Parse(string s) { if (s == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.s); return (DateTimeParse.Parse(s, DateTimeFormatInfo.CurrentInfo, DateTimeStyles.None)); @@ -1099,13 +1099,13 @@ namespace System // date and optionally a time in a culture-specific or universal format. // Leading and trailing whitespace characters are allowed. // - public static DateTime Parse(String s, IFormatProvider provider) + public static DateTime Parse(string s, IFormatProvider provider) { if (s == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.s); return (DateTimeParse.Parse(s, DateTimeFormatInfo.GetInstance(provider), DateTimeStyles.None)); } - public static DateTime Parse(String s, IFormatProvider provider, DateTimeStyles styles) + public static DateTime Parse(string s, IFormatProvider provider, DateTimeStyles styles) { DateTimeFormatInfo.ValidateStyles(styles, nameof(styles)); if (s == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.s); @@ -1122,7 +1122,7 @@ namespace System // date and optionally a time in a culture-specific or universal format. // Leading and trailing whitespace characters are allowed. // - public static DateTime ParseExact(String s, String format, IFormatProvider provider) + public static DateTime ParseExact(string s, string format, IFormatProvider provider) { if (s == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.s); if (format == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.format); @@ -1133,7 +1133,7 @@ namespace System // date and optionally a time in a culture-specific or universal format. // Leading and trailing whitespace characters are allowed. // - public static DateTime ParseExact(String s, String format, IFormatProvider provider, DateTimeStyles style) + public static DateTime ParseExact(string s, string format, IFormatProvider provider, DateTimeStyles style) { DateTimeFormatInfo.ValidateStyles(style, nameof(style)); if (s == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.s); @@ -1141,20 +1141,13 @@ namespace System return (DateTimeParse.ParseExact(s, format, DateTimeFormatInfo.GetInstance(provider), style)); } - // TODO https://github.com/dotnet/corefx/issues/25337: Remove this overload once corefx is updated to target the new signatures - public static DateTime ParseExact(ReadOnlySpan<char> s, string format, IFormatProvider provider, DateTimeStyles style) - { - if (format == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.format); - return ParseExact(s, (ReadOnlySpan<char>)format, provider, style); - } - public static DateTime ParseExact(ReadOnlySpan<char> s, ReadOnlySpan<char> format, IFormatProvider provider, DateTimeStyles style = DateTimeStyles.None) { DateTimeFormatInfo.ValidateStyles(style, nameof(style)); return DateTimeParse.ParseExact(s, format, DateTimeFormatInfo.GetInstance(provider), style); } - public static DateTime ParseExact(String s, String[] formats, IFormatProvider provider, DateTimeStyles style) + public static DateTime ParseExact(string s, string[] formats, IFormatProvider provider, DateTimeStyles style) { DateTimeFormatInfo.ValidateStyles(style, nameof(style)); if (s == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.s); @@ -1180,7 +1173,7 @@ namespace System { throw new ArgumentOutOfRangeException(nameof(value), SR.ArgumentOutOfRange_DateArithmetic); } - return new DateTime((UInt64)(ticks - valueTicks) | InternalKind); + return new DateTime((ulong)(ticks - valueTicks) | InternalKind); } // This function is duplicated in COMDateTime.cpp @@ -1239,9 +1232,9 @@ namespace System { return this; } - Boolean isDaylightSavings = false; - Boolean isAmbiguousLocalDst = false; - Int64 offset = TimeZoneInfo.GetUtcOffsetFromUtc(this, TimeZoneInfo.Local, out isDaylightSavings, out isAmbiguousLocalDst).Ticks; + bool isDaylightSavings = false; + bool isAmbiguousLocalDst = false; + long offset = TimeZoneInfo.GetUtcOffsetFromUtc(this, TimeZoneInfo.Local, out isDaylightSavings, out isAmbiguousLocalDst).Ticks; long tick = Ticks + offset; if (tick > DateTime.MaxTicks) { @@ -1260,59 +1253,55 @@ namespace System return new DateTime(tick, DateTimeKind.Local, isAmbiguousLocalDst); } - public String ToLongDateString() + public string ToLongDateString() { - return DateTimeFormat.Format(this, "D", DateTimeFormatInfo.CurrentInfo); + return DateTimeFormat.Format(this, "D", null); } - public String ToLongTimeString() + public string ToLongTimeString() { - return DateTimeFormat.Format(this, "T", DateTimeFormatInfo.CurrentInfo); + return DateTimeFormat.Format(this, "T", null); } - public String ToShortDateString() + public string ToShortDateString() { - return DateTimeFormat.Format(this, "d", DateTimeFormatInfo.CurrentInfo); + return DateTimeFormat.Format(this, "d", null); } - public String ToShortTimeString() + public string ToShortTimeString() { - return DateTimeFormat.Format(this, "t", DateTimeFormatInfo.CurrentInfo); + return DateTimeFormat.Format(this, "t", null); } - public override String ToString() + public override string ToString() { - return DateTimeFormat.Format(this, null, DateTimeFormatInfo.CurrentInfo); + return DateTimeFormat.Format(this, null, null); } - public String ToString(String format) + public string ToString(string format) { - return DateTimeFormat.Format(this, format, DateTimeFormatInfo.CurrentInfo); + return DateTimeFormat.Format(this, format, null); } - public String ToString(IFormatProvider provider) + public string ToString(IFormatProvider provider) { - return DateTimeFormat.Format(this, null, DateTimeFormatInfo.GetInstance(provider)); + return DateTimeFormat.Format(this, null, provider); } - public String ToString(String format, IFormatProvider provider) + public string ToString(string format, IFormatProvider provider) { - return DateTimeFormat.Format(this, format, DateTimeFormatInfo.GetInstance(provider)); + return DateTimeFormat.Format(this, format, provider); } - // TODO https://github.com/dotnet/corefx/issues/25337: Remove this overload once corefx is updated to target the new signatures - public bool TryFormat(Span<char> destination, out int charsWritten, string format, IFormatProvider provider) => - TryFormat(destination, out charsWritten, (ReadOnlySpan<char>)format, provider); - public bool TryFormat(Span<char> destination, out int charsWritten, ReadOnlySpan<char> format = default, IFormatProvider provider = null) => - DateTimeFormat.TryFormat(this, destination, out charsWritten, format, DateTimeFormatInfo.GetInstance(provider)); + DateTimeFormat.TryFormat(this, destination, out charsWritten, format, provider); public DateTime ToUniversalTime() { return TimeZoneInfo.ConvertTimeToUtc(this, TimeZoneInfoOptions.NoThrowOnInvalidTime); } - public static Boolean TryParse(String s, out DateTime result) + public static bool TryParse(string s, out DateTime result) { if (s == null) { @@ -1327,7 +1316,7 @@ namespace System return DateTimeParse.TryParse(s, DateTimeFormatInfo.CurrentInfo, DateTimeStyles.None, out result); } - public static Boolean TryParse(String s, IFormatProvider provider, DateTimeStyles styles, out DateTime result) + public static bool TryParse(string s, IFormatProvider provider, DateTimeStyles styles, out DateTime result) { DateTimeFormatInfo.ValidateStyles(styles, nameof(styles)); @@ -1346,7 +1335,7 @@ namespace System return DateTimeParse.TryParse(s, DateTimeFormatInfo.GetInstance(provider), styles, out result); } - public static Boolean TryParseExact(String s, String format, IFormatProvider provider, DateTimeStyles style, out DateTime result) + public static bool TryParseExact(string s, string format, IFormatProvider provider, DateTimeStyles style, out DateTime result) { DateTimeFormatInfo.ValidateStyles(style, nameof(style)); @@ -1359,25 +1348,13 @@ namespace System return DateTimeParse.TryParseExact(s, format, DateTimeFormatInfo.GetInstance(provider), style, out result); } - // TODO https://github.com/dotnet/corefx/issues/25337: Remove this overload once corefx is updated to target the new signatures - public static bool TryParseExact(ReadOnlySpan<char> s, string format, IFormatProvider provider, DateTimeStyles style, out DateTime result) - { - if (format == null) - { - result = default; - return false; - } - - return TryParseExact(s, (ReadOnlySpan<char>)format, provider, style, out result); - } - public static bool TryParseExact(ReadOnlySpan<char> s, ReadOnlySpan<char> format, IFormatProvider provider, DateTimeStyles style, out DateTime result) { DateTimeFormatInfo.ValidateStyles(style, nameof(style)); return DateTimeParse.TryParseExact(s, format, DateTimeFormatInfo.GetInstance(provider), style, out result); } - public static Boolean TryParseExact(String s, String[] formats, IFormatProvider provider, DateTimeStyles style, out DateTime result) + public static bool TryParseExact(string s, string[] formats, IFormatProvider provider, DateTimeStyles style, out DateTime result) { DateTimeFormatInfo.ValidateStyles(style, nameof(style)); @@ -1404,7 +1381,7 @@ namespace System { throw new ArgumentOutOfRangeException(nameof(t), SR.ArgumentOutOfRange_DateArithmetic); } - return new DateTime((UInt64)(ticks + valueTicks) | d.InternalKind); + return new DateTime((ulong)(ticks + valueTicks) | d.InternalKind); } public static DateTime operator -(DateTime d, TimeSpan t) @@ -1415,7 +1392,7 @@ namespace System { throw new ArgumentOutOfRangeException(nameof(t), SR.ArgumentOutOfRange_DateArithmetic); } - return new DateTime((UInt64)(ticks - valueTicks) | d.InternalKind); + return new DateTime((ulong)(ticks - valueTicks) | d.InternalKind); } public static TimeSpan operator -(DateTime d1, DateTime d2) @@ -1457,7 +1434,7 @@ namespace System // Returns a string array containing all of the known date and time options for the // current culture. The strings returned are properly formatted date and // time strings for the current instance of DateTime. - public String[] GetDateTimeFormats() + public string[] GetDateTimeFormats() { return (GetDateTimeFormats(CultureInfo.CurrentCulture)); } @@ -1465,7 +1442,7 @@ namespace System // Returns a string array containing all of the known date and time options for the // using the information provided by IFormatProvider. The strings returned are properly formatted date and // time strings for the current instance of DateTime. - public String[] GetDateTimeFormats(IFormatProvider provider) + public string[] GetDateTimeFormats(IFormatProvider provider) { return (DateTimeFormat.GetAllDateTimes(this, DateTimeFormatInfo.GetInstance(provider))); } @@ -1474,7 +1451,7 @@ namespace System // Returns a string array containing all of the date and time options for the // given format format and current culture. The strings returned are properly formatted date and // time strings for the current instance of DateTime. - public String[] GetDateTimeFormats(char format) + public string[] GetDateTimeFormats(char format) { return (GetDateTimeFormats(format, CultureInfo.CurrentCulture)); } @@ -1482,7 +1459,7 @@ namespace System // Returns a string array containing all of the date and time options for the // given format format and given culture. The strings returned are properly formatted date and // time strings for the current instance of DateTime. - public String[] GetDateTimeFormats(char format, IFormatProvider provider) + public string[] GetDateTimeFormats(char format, IFormatProvider provider) { return (DateTimeFormat.GetAllDateTimes(this, format, DateTimeFormatInfo.GetInstance(provider))); } @@ -1557,7 +1534,7 @@ namespace System throw new InvalidCastException(SR.Format(SR.InvalidCast_FromTo, "DateTime", "Double")); } - Decimal IConvertible.ToDecimal(IFormatProvider provider) + decimal IConvertible.ToDecimal(IFormatProvider provider) { throw new InvalidCastException(SR.Format(SR.InvalidCast_FromTo, "DateTime", "Decimal")); } @@ -1567,7 +1544,7 @@ namespace System return this; } - Object IConvertible.ToType(Type type, IFormatProvider provider) + object IConvertible.ToType(Type type, IFormatProvider provider) { return Convert.DefaultToType((IConvertible)this, type, provider); } @@ -1575,7 +1552,7 @@ namespace System // Tries to construct a DateTime from a given year, month, day, hour, // minute, second and millisecond. // - internal static Boolean TryCreate(int year, int month, int day, int hour, int minute, int second, int millisecond, out DateTime result) + internal static bool TryCreate(int year, int month, int day, int hour, int minute, int second, int millisecond, out DateTime result) { result = DateTime.MinValue; if (year < 1 || year > 9999 || month < 1 || month > 12) |