Xamarin Public Jenkins (auto-signing) e79aa3c0ed Imported Upstream version 4.6.0.125
Former-commit-id: a2155e9bd80020e49e72e86c44da02a8ac0e57a4
2016-08-03 10:59:49 +00:00

53 lines
1.8 KiB
C#

//------------------------------------------------------------------------------
// <copyright file="FileChangesMonitor.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
//------------------------------------------------------------------------------
namespace System.Web.Util {
using System;
internal sealed class DateTimeUtil {
private DateTimeUtil() {}
const long FileTimeOffset = 504911232000000000;
static readonly DateTime MinValuePlusOneDay = DateTime.MinValue.AddDays(1);
static readonly DateTime MaxValueMinusOneDay = DateTime.MaxValue.AddDays(-1);
static internal DateTime FromFileTimeToUtc(long filetime) {
long universalTicks = filetime + FileTimeOffset;
// Dev10 733288: Caching: behavior change for CacheDependency when using UseMemoryCache=1
// ObjectCacheHost converts DateTime to a DateTimeOffset, and the conversion requires
// that DateTimeKind be set correctly
return new DateTime(universalTicks, DateTimeKind.Utc);
}
static internal DateTime ConvertToUniversalTime(DateTime localTime) {
if (localTime < MinValuePlusOneDay) {
return DateTime.MinValue;
}
if (localTime > MaxValueMinusOneDay) {
return DateTime.MaxValue;
}
return localTime.ToUniversalTime();
}
static internal DateTime ConvertToLocalTime(DateTime utcTime) {
if (utcTime < MinValuePlusOneDay) {
return DateTime.MinValue;
}
if (utcTime > MaxValueMinusOneDay) {
return DateTime.MaxValue;
}
return utcTime.ToLocalTime();
}
}
}