Reserve Time.now or its equavlent to jobs, controllers, or what not at the edge of your application.
Watch out when using NOW() in your db. Not that you shouldn’t but it might be surprising when you do.
Would you be so kind as to elaborate on this?
It was always my thought that NOW() was the more sensible approach as it would capture time in the execution order from a more centralized source (the db server). Where having the origin of a transaction setting at time would get me when, on the origin server the query was initiated.
There is nothing wrong with using NOW(), in of itself, and it maybe the best thing to do.
But it may lead to surprising results when say you have an application that has mocked out time for a specific time, but you get db results for the current time. It introduces another clock into your system.
I have found most of the time we were using NOW() we could pass the time into the query and create a more understandable chain of code.
We use dependency injection wherever the service is required.
With this, we can manage 2 things
1. The service can go faster or slower than the real time by changing the timer's interval so we can simulate time depend behaviour in the app while testing.
2. We can mock the service when testing with a simple counter that's increased each time “.now()" is called.
https://learn.microsoft.com/en-us/dotnet/core/whats-new/dotn...
Though most people were rolling their own version of it before this.