Skip to main content
Python Software Foundation 20th Year Anniversary Fundraiser  Donate today!

Template name resolution for Django class-based views

Project description


Mock dates for Django.

Version 0.2

**Warning**: Until release of version 1, API is bound to change.


Imagine you have to test a feature that calculates arrears based on days passed from the due date. You probably want to suggest the amount based on days until **today**. Then you want to do some manual testing and try it with different dates. That's where timesickle comes in. You probably *don't* want to do a nasty::

import datetime
# ...
if __debug__:
date =
date =, 1, 1)
# don't do this ^

Also, if the mock date is to be checked from different points in the code, you don't want to repeat the above code.

To transit easily from a "real today" and a "mock today" in different parts of your code, use ``timesickle``.

Recommendations for use of this piece of software:

Be careful with this technique, though. I would encourage you to write backend functions that receive dates instead of calculating "now" or "today" inside their bodies. The resolution of what "today" is should be left to the enclosing logic. For example, have model instance fields be told the date they should work with, but calculate this date in the views.


**Disclaimer.** Don't use this software for a full-scale project.


*A more proper installation might be due.*

To install the latest version, run::

pip install git+git://

In ````, add ``'timesickle'`` under ``INSTALLED_APPS``::

# django
# third party
# my apps

If you want to install a previous version, go figure. I don't know how to do that (but if you know, I don't mind you teaching me).


To test the installation, run::

python test "timesickle"

If the tests fail, you should::

1. not use my software (|||❛︵❛.)
2. tell me, that is, file an issue on this repository o(^^o


In ````, set a ``MOCK_NOW`` object. This will define the variables in the ``timesickle`` module: "now", "today", "tomorrow", "tomorrow_sametime", "yesterday", and "yesterday_sametime"::

import datetime

MOCK_NOW = datetime.datetime(2014, 05, 17, 18, 30, 0)

The above will set the mock date and time to IHOT, 6:30 PM.

If you don't set the ``MOCK_NOW`` object, timesickle's dates will be based on the server's current time (````).

Depending on your logging settings, if you let the ``"INFO"`` logging level print to console, you will see the calculated values for the forementioned variables.

You can also set extra dates or date-times using a dictionary called "SICKLE_DATES" in your settings::


'pichincha_battle':, 5, 24),

Then, you can check this dates from ``timesickle.dates`` as either an attribute or a dictionary lookup (you might prefer ``\w+`` names to look for them more comfortably)::

import timesickle


Use in templates

You can also use the tags included in the library. As far as they intend, they work pretty similar to the ``{% now "SOMEFORMAT" %}`` tag::

{% load sickletime %}
Right now it is: {% sicklenow "SHORT_DATETIME_FORMAT" %},
then obviously today is {% sickletoday "SHORT_DATE_FORMAT" %}


This mocking if dates is intended for small scale projects. It doesn't even consider time zones, so be careful. *Be specially careful if you need time-zone-aware functionality*.

We could also use a database to store the ``timesickle.dates`` objects, but this makes the whole project more complex and more difficult to maintain. This is only for small-scale development and test purposes.

Project details

Release history Release notifications | RSS feed

This version


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for django-timesickle, version 0.2
Filename, size File type Python version Upload date Hashes
Filename, size django-timesickle-0.2.tar.gz (5.5 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page