DateTimeUtil.cs source code in C# .NET

Source code for the .NET framework in C#

                        

Code:

/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / xsp / System / Web / Util / DateTimeUtil.cs / 1305376 / DateTimeUtil.cs

                            //------------------------------------------------------------------------------ 
// 
//     Copyright (c) Microsoft Corporation.  All rights reserved.
// 
//----------------------------------------------------------------------------- 

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();
        }
    }
} 

 

// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
//------------------------------------------------------------------------------ 
// 
//     Copyright (c) Microsoft Corporation.  All rights reserved.
// 
//----------------------------------------------------------------------------- 

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();
        }
    }
} 

 

// File provided for Reference Use Only by Microsoft Corporation (c) 2007.

                        

Link Menu

Network programming in C#, Network Programming in VB.NET, Network Programming in .NET
This book is available now!
Buy at Amazon US or
Buy at Amazon UK