Skip to content

Instantly share code, notes, and snippets.

@SlyNet
Created June 7, 2012 14:36
Show Gist options
  • Save SlyNet/2889138 to your computer and use it in GitHub Desktop.
Save SlyNet/2889138 to your computer and use it in GitHub Desktop.
Unit testing friendly datetime
using System;
namespace Core.Utils
{
public static class SystemTime
{
public static Func<DateTime> Engine { private get; set; }
static SystemTime()
{
SetDefaultEngine();
}
public static void SetDefaultEngine()
{
Engine = () => DateTime.Now;
}
public static DateTime Now
{
get
{
return Engine();
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment