I very much doubt that there's any nuget package for anything quite so trivial - a single interface and probably two implementations ("system" clock and a fake one for testing).
If you're doing one of these yourself, I would strongly consider making the clock return a DateTimeOffset
instead of a DateTime
, or at least make it wrap DateTime.UtcNow
... DateTime.Now
is a problem waiting to happen...
However, Noda Time contains all of this out of the box. You probably don't want the whole of Noda Time just for this reason, mind you...
(There's a Noda Time nuget package, but it's definitely pre-release. I need to update it to a 0.2 version at some point, but it's still not at the v1 level yet. Getting there though...)
If you want a really cheap-and-cheerful way of expressing the dependency, you could always take a Func<DateTime>
or Func<DateTimeOffset>
wherever you normally express dependencies. The interface approach is cleaner though :)