handling of system time improved, unit tests added (code for windows is untested)