I'm writing a library that reads Time in and out of a database. As part of that, I am writing unit tests the output of $ for Time. $ does not take extra parameters by its nature.
The problem is that $ generates a string in my local time zone. For myself, that kind of works. But if/when the library is released, asking each developer to change their timezone to run nimble test is not particularly friendly or ideal.
I've come up with a hack-ish workaround for now.
But, is there a way to override the timezone in nim? Or perhaps a command-line switch to place in the t*.cfg files?
I do this in one of my Emacs lisp projects, I set the TZ environment variable to UTC in my test config.
So when the tests run on Travis, it thinks that it lives in the UTC zone, and all time stamps are created accordingly.
That way, you don't need to hardcode the time zone in your Nim code, and all time manipulation code will default to the local time zone (set by TZ).. I believe.
I haven't tried this with Nim, so just try it out :)
Thanks for the helpful work-around. Still can't test the $ function without manipulating an environment variable, but that isn't the end of the world is suppose.
Perhaps, if I get motivated, I'll make a PR for a compiler variable for the times module that allows for an override for $.
Shameless plug for my timezone library: https://github.com/treeform/chrono It does not rely on any operating system or clib functions. So there is no need to set environmental variables.
Simply convert what your DB gives you to a Calendar object and $. Will work same on any computer - event compiles to javascript.