Here is a handy class that will help with unit testing any references to DateTime.Now.

public static class SystemTime{ public static Func<DateTime> Now = () => DateTime.Now(); public static Func<DateTime> UtcNow = () => DateTime.UtcNow(); public static Func<DateTimeOffset> OffsetNow = () => DateTimeOffset.Now; }
Code language: PHP (php)

This is helpful when you need to test certain results from DateTime.Now. Instead of referencing DateTime.Now in your code, you would reference SystemTime.Now.

var _date = SystemTime.Now();
Code language: JavaScript (javascript)

References:
https://ardalis.com/unit-testing-time/

https://ayende.com/blog/3408/dealing-with-time-in-tests