Created
August 27, 2014 14:50
-
-
Save jakesays-old/ad521c9af8650f3b39d0 to your computer and use it in GitHub Desktop.
DateTime abstraction
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Diagnostics; | |
using Apex.Utility.Internal; | |
namespace Utility | |
{ | |
/// <summary> | |
/// The SystemTime class provides a simple abstraction over DateTime.Now. | |
/// It uses a time provider to generate the current time. The default | |
/// provider just fowards to DateTime.Now/UtcNow. | |
/// </summary> | |
public static class SystemTime | |
{ | |
public static DateTime Now | |
{ | |
[DebuggerStepThrough] | |
get { return TimeProvider.CurrentProvider.Now; } | |
} | |
public static DateTime UtcNow | |
{ | |
[DebuggerStepThrough] | |
get { return TimeProvider.CurrentProvider.UtcNow; } | |
} | |
} | |
} | |
using System; | |
namespace Utility.Internal | |
{ | |
public abstract class TimeProvider | |
{ | |
public static TimeProvider CurrentProvider = new DefaultTimeProvider(); | |
public abstract DateTime Now { get; } | |
public abstract DateTime UtcNow { get; } | |
} | |
} | |
using System; | |
using System.Diagnostics; | |
namespace Utility.Internal | |
{ | |
public class DefaultTimeProvider : TimeProvider | |
{ | |
public override DateTime Now | |
{ | |
[DebuggerStepThrough] | |
get { return DateTime.Now; } | |
} | |
public override DateTime UtcNow | |
{ | |
[DebuggerStepThrough] | |
get { return DateTime.UtcNow; } | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment