From charlesreid1

Mac OS X

Installing Libfaketime

It is really easy to install libfaketime on Mac OS X: use homebrew.

$ brew install libfaketime

The location of the libfaketime library is then

/usr/local/lib/faketime/libfaketime.1.dylib

and the location of the binary program faketime, which provides a convenient wrapper for using libfaketime, is then

/usr/local/bin/faketime

Documentation on Usage

Using libfaketime on Mac OS X is different from using Libfaketime on Linux, so you need to read both the README and the README.OSX file.

Link to the readme: https://github.com/wolfcw/libfaketime/blob/master/README

Link to the OS X readme: https://github.com/wolfcw/libfaketime/blob/master/README.OSX

Testing Libfaketime

To test out libfaketime, I decided I would try running a couple of programs through the faketime wrapper.

Date Doesn't Work

The examples in the readme files all use the system's /bin/date program. Unfortunately, this did not work for me on Mac OS X 10.11.5, and I think the reason is, it requires the /bin/date program to be dynamically linked to system libraries that request the date, which allows you to swap out the system library for the custom libfaketime library. However, with the latest operating system release, Apple must have changed /bin/date to be statically linked, probably because they saw this as a potential vulnerability, or maybe because they want to make life difficult and annoying for programmers by constantly changing everything with every new operating system release.

Python Works

You can use libfaketime to fool Python into thinking it is in the past. I ran the python binary through the faketime wrapper, and then used the datetime library to print out the current date and time. Check it out:

$ faketime '2008-12-25 08:00:00' python
Python 2.7.10 (v2.7.10:15c95b7d81dc, May 23 2015, 09:33:12)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import datetime
>>> print datetime.datetime.now()
2008-12-25 08:00:12.829915
>>>

C Works

This also works when running a simple, compiled C program that prints the current date and time. Here is the simple program:

#include <stdio.h>
#include <time.h>

/*
 * This program prints the current date and the current time.
 */

int main(void) {

    // get the current time, C time type
    time_t t = time(NULL);

    // chunk it up into a struct
    struct tm tm = *localtime(&t);

    // print each chunk
    printf("The current date is: %0.04d-%0.02d-%0.02d\n", tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday);
    printf("The current time is: %0.02d:%0.02d:%0.02d\n", tm.tm_hour, tm.tm_min, tm.tm_sec);

    return 0;
}

and the output:

$ gcc what_time_is_it.c -o whattime
$ faketime '2008-12-25 08:00:00' ./whattime
The current date is: 2008-12-25
The current time is: 08:00:00

Note that this was run on July 9, 2016. Ziiiiing!