Lib dateoffset provides a very simple way to run a single application or container with a different date, without changing the system clock.
It's useful for testing and debugging code that are time-dependant, like databases, certificates, and all sort of business logic that involves dates.
If you are looking for a portable and full featured solution, you might opt for the excellent libfaketime.
Unfortunately the way libfaketime works clash with some applications using jemalloc as memory allocator, which apperas to be the case of Microsoft SQL Server for Linux and many other applications.
Lib dateoffset solves it by eliminating memory allocations caused by dlsym
and directly calls Linux clock_gettime
syscall.
I strongly suggest you to try libfaketime first before using this one.
Just like libfaketime, the basic way of running any command/program with Lib dateoffset is getting it loaded by system's linker using the environment variable LD_PRELOAD
.
However, unlike libfaketime, Lib dateoffset is much more limitted and has just one way to define the date, through the environment variable DATE_OFFSET
with the start date in epoch format (seconds since 1970-01-01 00:00:00 UTC). You can use the command date to convert a date in format yyyy-MM-dd
to seconds.
Examples:
a) Setting the environment variables
export LD_PRELOAD=/path/to/dateoffset.so
export DATE_OFFSET=$(date -d "2012/12/21 12:00:00" '+%s')
# (now run any command you want) #
b) Or it can be done by specifying it on the command line itself:
LD_PRELOAD=/path/to/dateoffset.so \
DATE_OFFSET=$(date -d "2019-10-30 00:00:00" '+%s') \
# your_command_here #
c) Changing just the date, but keeping the time unchanged
LD_PRELOAD=/path/to/dateoffset.so \
DATE_OFFSET=$(($(date -d "2016-10-12" '+%s') + ($(date '+%s') % (24*60*60)))) \
# your_command_here #
d) Dockerfile
ENV LD_PRELOAD=/path/to/dateoffset.so
ENV DATE_OFFSET=2090-07-04
ENTRYPOINT ["/my-app"]
- This project is a free and unencumbered software released into the public domain. Plese visit unlicense.org for more details.