Linux: Set timezone offset that doesn't exist?
The tool you're looking for is faketime
.
faketime 'yesterday 9am' /bin/date
faketime '2018-10-25 16:45' /bin/date
It is possible to use any timezone name that doesn't exist and set the time up to +- 24 hours. Assuming that MYFAKETIME
doesn't exist as a valid timezone (it doesn't yet, but may be defined in the future (very unlikely)), then, this is possible:
isaac@mail:~$ date
Sun Sep 30 01:22:05 EST 2018
isaac@mail:~$ TZ=MYFAKETIME date
Sun Sep 30 06:22:43 MYFAKETIME 2018
isaac@mail:~$ TZ=MYFAKETIME+1 date
Sun Sep 30 05:22:56 MYFAKETIME 2018
isaac@mail:~$ TZ=MYFAKETIME+10 date
Sat Sep 29 20:23:00 MYFAKETIME 2018
isaac@mail:~$ TZ=MYFAKETIME+20 date
Sat Sep 29 10:23:05 MYFAKETIME 2018
isaac@mail:~$ TZ=MYFAKETIME+24 date
Sat Sep 29 06:23:08 MYFAKETIME 2018
isaac@mail:~$ TZ=MYFAKETIME+48 date
Sat Sep 29 06:23:14 MYFAKETIME 2018
isaac@mail:~$ TZ=MYFAKETIME+96 date
Sat Sep 29 06:23:25 MYFAKETIME 2018
isaac@mail:~$
Note that timezones above 24 just don't work. They do not change the time but are limited to the range -24
to +24
. From 21.4.7 Specifying the Time Zone with TZ
The first format is used when there is no Daylight Saving Time (or summer time) in the local time zone:
std offset
The std string specifies the name of the time zone. It must be three or more characters long and must not contain a leading colon, embedded digits, commas, nor plus and minus signs. There is no space character separating the time zone name from the offset, so these restrictions are necessary to parse the specification correctly.
The offset specifies the time value you must add to the local time to get a Coordinated Universal Time value. It has syntax like [+|-]hh[:mm[:ss]]. This is positive if the local time zone is west of the Prime Meridian and negative if it is east. The hour must be between 0 and 24, and the minute and seconds between 0 and 59.
So, there is no way to change the time to "days into the future" using the TZ variable.
The real solution is to use the faketime
utility (from the package of the same name).
That will allow you to do:
isaac@mail:~$ faketime '2008-12-24 08:15:42' /bin/date
Wed Dec 24 08:15:42 EST 2008
isaac@mail:~$ date
Sun Sep 30 01:44:29 EST 2018
Just set the TZ
variable. Positive values go East, so is behind GMT.
eg
$ TZ=GMT date
Sat Sep 29 19:12:30 GMT 2018
$ TZ=FAKEEAST+15 date
Sat Sep 29 04:12:36 FAKEEAST 2018
$ TZ=FAKEWEST-15 date
Sun Sep 30 10:12:41 FAKEWEST 2018
This will only let you go +/- 24 hours.