3

In order to resolve a specific timezone related bug on a software project that I'm working on, I'm trying to replicate a change on the system's clock using timedatectl to check my software behavior.

I'm trying to achieve that by running

timedatectl set-timezone America/New_York
timedatectl set-local-rtc 1
timedatectl set-ntp false
timedatectl set-time "2017-03-12 01:58:50" && hwclock -w

When I do that and run timedatectlright after, I get the expected following time:

Local time: Sun 2017-03-12 01:58:51 EST
Universal time: Sun 2017-03-12 06:58:51 UTC
RTC time: Sun 2017-03-12 01:58:51
Time zone: America/New_York (EST, -0500)
System clock synchronized: no
systemd-timesyncd.service active: no
RTC in local TZ: yes

However, 10 seconds after this, when the minute changes (to xx:59), the local and universal time kind of "reboot" to the current time

Local time: Wed 2019-08-07 21:01:41 EDT
Universal time: Thu 2019-08-08 01:01:41 UTC
RTC time: Sun 2017-03-12 01:58:57
Time zone: America/New_York (EDT, -0400)
System clock synchronized: no
systemd-timesyncd.service active: no
RTC in local TZ: yes

What am I missing here?

My setup is an Vagrant Ubuntu 18 VM (Linux vagrant 4.15.0-51 / vm box "bento/ubuntu-18.04").

| improve this question | | | | |
  • You may well find that your VM time is synchronised to your host's time. Not familiar with Vagrant so can't point you to a solution. – roaima Aug 8 '19 at 8:42
5

This won’t explain the behaviour you’re seeing, but it should answer the question in the title.

Instead of changing the system’s time, you could use a tool such as faketime and the TZ environment variable:

$ date; faketime -f -15d date; TZ=America/New_York faketime -f -15d date
Thu  8 Aug 10:21:13 CEST 2019
Wed 24 Jul 10:21:13 CEST 2019
Wed 24 Jul 04:21:13 EDT 2019

This will allow you to run your program with its own time zone, date and time, without affecting the rest of the system.

Note that as it uses a $LD_PRELOAD hack to inject code in applications, it won't work for statically linked executables or setuid/setgid executables.

| improve this answer | | | | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.