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.Now
and related functions.
You should be passing in a DateTime
to any function that relies on it. Any place you use DateTime.Now
or DateTime.Today
(and such) is a place where you should be passing in the date.
This allows you to test for different DateTime
values, will make your code more testable and remove the temporal dependency.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With