Time classes for R, w/ time mocking capability via timefuzz
Why? - Some programming languages support monkey patching. However, R does not officially allow this (there’s a way to do it, but it’s a hack). Therefore, the only way that I can think of to “mock time” is to use a different set of time classes/objects. That is, we can’t just mock time using
Sys.Date() directly as there’s no way to monkey patch the code behind that function. Some may say it’s good that R doesn’t officially support monkey patching; there’s definitely upsides; but a downside is that mocking things like time becomes difficult.
clock()is designed for setting a specific time
now()is designed for getting the current time AND is mockable
sys_date()are drop in replacements for
Sys.Date()AND are mockable
See the docs to get started: https://docs.ropensci.org/clock