@@ -77,7 +77,7 @@ private static unsafe DateTime FromFileTimeLeapSecondsAware(ulong fileTime)
77
77
{
78
78
throw new ArgumentOutOfRangeException ( nameof ( fileTime ) , SR . ArgumentOutOfRange_DateTimeBadTicks ) ;
79
79
}
80
- return CreateDateTimeFromSystemTime ( in time , fileTime % TicksPerMillisecond ) ;
80
+ return CreateDateTimeFromSystemTime ( in time , fileTime % TimeSpan . TicksPerMillisecond ) ;
81
81
}
82
82
83
83
private static unsafe ulong ToFileTimeLeapSecondsAware ( long ticks )
@@ -112,20 +112,20 @@ private static DateTime CreateDateTimeFromSystemTime(in Interop.Kernel32.SYSTEMT
112
112
ReadOnlySpan < uint > days = IsLeapYear ( ( int ) year ) ? DaysToMonth366 : DaysToMonth365 ;
113
113
int month = time . Month - 1 ;
114
114
uint n = DaysToYear ( year ) + days [ month ] + time . Day - 1 ;
115
- ulong ticks = n * ( ulong ) TicksPerDay ;
115
+ ulong ticks = n * ( ulong ) TimeSpan . TicksPerDay ;
116
116
117
- ticks += time . Hour * ( ulong ) TicksPerHour ;
118
- ticks += time . Minute * ( ulong ) TicksPerMinute ;
117
+ ticks += time . Hour * ( ulong ) TimeSpan . TicksPerHour ;
118
+ ticks += time . Minute * ( ulong ) TimeSpan . TicksPerMinute ;
119
119
uint second = time . Second ;
120
120
if ( second <= 59 )
121
121
{
122
- ulong tmp = second * ( uint ) TicksPerSecond + time . Milliseconds * ( uint ) TicksPerMillisecond + hundredNanoSecond ;
122
+ ulong tmp = second * ( uint ) TimeSpan . TicksPerSecond + time . Milliseconds * ( uint ) TimeSpan . TicksPerMillisecond + hundredNanoSecond ;
123
123
return new DateTime ( ticks + tmp | KindUtc ) ;
124
124
}
125
125
126
126
// we have a leap second, force it to last second in the minute as DateTime doesn't account for leap seconds in its calculation.
127
127
// we use the maxvalue from the milliseconds and the 100-nano seconds to avoid reporting two out of order 59 seconds
128
- ticks += TicksPerMinute - 1 | KindUtc ;
128
+ ticks += TimeSpan . TicksPerMinute - 1 | KindUtc ;
129
129
return new DateTime ( ticks ) ;
130
130
}
131
131
@@ -166,7 +166,7 @@ private static unsafe bool GetSystemSupportsLeapSeconds()
166
166
( ( delegate * unmanaged[ SuppressGCTransition ] < long * , void > ) pfnGetSystemTime ) ( & systemTimeResult ) ;
167
167
( ( delegate * unmanaged[ SuppressGCTransition ] < long * , void > ) pfnGetSystemTimePrecise ) ( & preciseSystemTimeResult ) ;
168
168
169
- if ( Math . Abs ( preciseSystemTimeResult - systemTimeResult ) <= 100 * TicksPerMillisecond )
169
+ if ( Math . Abs ( preciseSystemTimeResult - systemTimeResult ) <= 100 * TimeSpan . TicksPerMillisecond )
170
170
{
171
171
pfnGetSystemTime = pfnGetSystemTimePrecise ; // use the precise version
172
172
break ;
@@ -194,7 +194,7 @@ private static unsafe DateTime UpdateLeapSecondCacheAndReturnUtcNow()
194
194
// cache will return incorrect values.
195
195
196
196
Debug . Assert ( SystemSupportsLeapSeconds ) ;
197
- Debug . Assert ( LeapSecondCache . ValidityPeriodInTicks < TicksPerDay - TicksPerSecond , "Leap second cache validity window should be less than 23:59:59." ) ;
197
+ Debug . Assert ( LeapSecondCache . ValidityPeriodInTicks < TimeSpan . TicksPerDay - TimeSpan . TicksPerSecond , "Leap second cache validity window should be less than 23:59:59." ) ;
198
198
199
199
ulong fileTimeNow ;
200
200
LeapSecondCache . s_pfnGetSystemTimeAsFileTime ( & fileTimeNow ) ;
@@ -203,7 +203,7 @@ private static unsafe DateTime UpdateLeapSecondCacheAndReturnUtcNow()
203
203
// First, convert the FILETIME to a SYSTEMTIME.
204
204
205
205
Interop . Kernel32 . SYSTEMTIME systemTimeNow ;
206
- ulong hundredNanoSecondNow = fileTimeNow % TicksPerMillisecond ;
206
+ ulong hundredNanoSecondNow = fileTimeNow % TimeSpan . TicksPerMillisecond ;
207
207
208
208
// We need the FILETIME and the SYSTEMTIME to reflect each other's values.
209
209
// If FileTimeToSystemTime fails, call GetSystemTime and try again until it succeeds.
@@ -267,7 +267,7 @@ private static unsafe DateTime UpdateLeapSecondCacheAndReturnUtcNow()
267
267
}
268
268
269
269
// StartOfValidityWindow = MidnightUtc + 23:59:59 - ValidityPeriod
270
- fileTimeAtStartOfValidityWindow = fileTimeAtBeginningOfDay + ( TicksPerDay - TicksPerSecond ) - LeapSecondCache . ValidityPeriodInTicks ;
270
+ fileTimeAtStartOfValidityWindow = fileTimeAtBeginningOfDay + ( TimeSpan . TicksPerDay - TimeSpan . TicksPerSecond ) - LeapSecondCache . ValidityPeriodInTicks ;
271
271
if ( fileTimeNow - fileTimeAtStartOfValidityWindow >= LeapSecondCache . ValidityPeriodInTicks )
272
272
{
273
273
// If we're inside this block, then we slid the validity window back so far that the current time is no
@@ -295,7 +295,7 @@ private static unsafe DateTime UpdateLeapSecondCacheAndReturnUtcNow()
295
295
return CreateDateTimeFromSystemTime ( systemTimeNow , hundredNanoSecondNow ) ;
296
296
}
297
297
298
- dotnetDateDataAtStartOfValidityWindow = CreateDateTimeFromSystemTime ( systemTimeAtBeginningOfDay , 0 ) . _dateData + ( TicksPerDay - TicksPerSecond ) - LeapSecondCache . ValidityPeriodInTicks ;
298
+ dotnetDateDataAtStartOfValidityWindow = CreateDateTimeFromSystemTime ( systemTimeAtBeginningOfDay , 0 ) . _dateData + ( TimeSpan . TicksPerDay - TimeSpan . TicksPerSecond ) - LeapSecondCache . ValidityPeriodInTicks ;
299
299
}
300
300
301
301
// Finally, update the cache and return UtcNow.
@@ -330,7 +330,7 @@ static DateTime LowGranularityNonCachedFallback()
330
330
private sealed class LeapSecondCache
331
331
{
332
332
// The length of the validity window. Must be less than 23:59:59.
333
- internal const ulong ValidityPeriodInTicks = TicksPerMinute * 5 ;
333
+ internal const ulong ValidityPeriodInTicks = TimeSpan . TicksPerMinute * 5 ;
334
334
335
335
// The FILETIME value at the beginning of the validity window.
336
336
internal ulong OSFileTimeTicksAtStartOfValidityWindow ;
0 commit comments