4 ms·
I'm not sure how that would work. Can you give an example?
by bruce343434 3y ago
I'm not sure how that would work. Can you give an example?
- EdwardDiego 3y agoHave a look at this method on Java's Instant class for an example. https://docs.oracle.com/javase/8/docs/api/java/time/Instant.html#now-java.time.Clock- https://docs.oracle.com/javase/8/docs/api/java/time/Instant.... Code under test creates Instant, so long as it uses the Clock you've passed in, you'll control how it determines when now() is. You've got several built-in testing clocks like this one[1], but can also implement your own. [1]: https://docs.oracle.com/javase/8/docs/api/java/time/Clock.html#fixed-java.time.Instant-java.time.ZoneId- https://docs.oracle.com/javase/8/docs/api/java/time/Clock.ht...
- skrebbel 3y agoJust a class (or struct or module or whatever your language has for that) that has a “now()” method which returns the current time. And then replace all your calls that do Date.now() with clock.now() and then you can make “now” be whatever you want.