Faking the date for a specific shell session

I'm certainly trying to achieve something weird here, but I want to fake the date locally for a shell session on GNU/Linux. I need to black-box test how a program behaves at different dates, and modifying the system-wide date can have unwanted side effects (cron jobs, messed up logs, etc).

Any ideas ?


You can just use executable faketime (from ubuntu repositories sudo apt-get install faketime) by:

faketime -f "-15d" date

Or even fake time in whole shell by

faketime -f "-15d" bash -l

Haven't tried this one out yet. But if this is current is looks like someone already wrote the library you can preload with libfaketime.

The basic usage is:

user@host> LD_PRELOAD=/usr/local/lib/libfaketime.so.1 FAKETIME="-15d" date
Mon Nov  8 12:01:12 CEST 2007

You can use ltrace to make sure all the time functions your application uses are covered.