We have a very massive system where reports are run off dates from specific days through to today’s date using various definitions of “GenerateSalesReport(DateStart, Date.Now)”.
For debugging purposes, I want to simulate reports that occurred in the past so I need to change the object “Date.Now” to a specific date from the past on my development environment. Is it possible to override date.Now?
That is one of the failings of
DateTime.Nowand related functions.You should be passing in a
DateTimeto any function that relies on it. Any place you useDateTime.NoworDateTime.Today(and such) is a place where you should be passing in the date.This allows you to test for different
DateTimevalues, will make your code more testable and remove the temporal dependency.