4 ms·
> DateTime.Now I've got this in several places. I have code that needs to check if other date is within two weeks of today. I have test data. I could either
by shagie 2y ago
> DateTime.Now
I've got this in several places.
I have code that needs to check if other date is within two weeks of today. I have test data.
I could either modify the test data based on today's date (adding other logic to tests that itself could be faulty), do something while loading the test data... or have the date to be used for comparisons be injected in.
That date is July 1, 2018. It was selected so that I didn't have difficulty with reasoning about the test data and "is this a leap year?" or across a year boundary on January 1.
Its not a "I don't trust it to work across those conditions" but rather a "it is easier to reason about what is 60 days before or after July 1 than 60 days before or after January 1.
And returning to the point - injectable dates for "now" are very useful. Repeatable and reasonable tests save time.