Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

* in C++.

On Python, just use freezegun to inject controllable timestamps in response to calls to time methods.

https://github.com/spulec/freezegun



The Ruby equivalent is Timecop

https://github.com/travisjeffery/timecop

Dynamic languages have the advantage to be able to rewrite the standard library classes at runtime.


I used to change an objects class itself in runtime in JS by changing its __proto__ property.

I don’t think that works anymore, but at the time I could create plain value objects and later make them class instantiations (on a small system way back when, this was a nice speed up due to a now uncommon pattern of having data first and waiting for the classes to load).


Other languages can use LD_PRELOAD (or DLL injection on Windows) as long as the binary isn't statically linked.

See other comments in the thread about libfaketime.


I read the documentation about libfaketime and I saw that it doesn't work in combination with other libraries that also play with LD_PRELOAD. Timecop could fail if something else also wraps the date and time classes but its block scoped form should keep working. I didn't check. Furthermore I don't know what's out there that does it. I should write my own code.


Freezegun is pretty much unmaintained. You want time-machine https://github.com/adamchainz/time-machine




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: