iTranslated by AI
The content below is an AI-generated translation. This is an experimental feature, and may contain errors. View original article
⏰
One-liner to install libfaketime
This is a small tip, but I feel like I use it every few years, so I'm making a note.
# A suitable container
$ docker run --rm -it python bash
# Installation
root@8a7e5352e6cc:/# (cd /&& git clone https://github.com/wolfcw/libfaketime.git && cd /libfaketime/src && make install && echo -e '/usr/local/lib/faketime/libfaketime.so.1' >> /etc/ld.so.preload)
Cloning into 'libfaketime'...
...snip...
install -Dm0755 faketime "/usr/local/bin/faketime"
# Normal date
root@8a7e5352e6cc:/# date
Mon Jun 28 12:16:16 UTC 2021
# Faked date
root@8a7e5352e6cc:/# FAKETIME="@2112-09-03 00:00:00" date
Sat Sep 3 00:00:00 UTC 2112
# Also works for languages
root@7365cddcbfc4:/# FAKETIME="@2112-09-03 00:00:00" python
Python 3.9.5 (default, Jun 23 2021, 15:01:51)
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import datetime
>>> datetime.datetime.now()
datetime.datetime(2112, 9, 3, 0, 0, 12, 488212)
That's it 😌
Discussion