Giter Club home page Giter Club logo

dateoffset's Introduction

Lib dateoffset

Modifies the system time for a single application or container through Linux syscall

1. What is it

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.

2. Motivation

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.

3. Usage

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"]

License

  • This project is a free and unencumbered software released into the public domain. Plese visit unlicense.org for more details.

dateoffset's People

Contributors

batiati avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

hhm-shy

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.