jbalogh / jingo

An adapter for using Jinja2 templates with Django.
http://readthedocs.org/docs/jingo/en/latest/
BSD 3-Clause "New" or "Revised" License
178 stars 45 forks source link

datetime helper breaks on Windows #23

Open squiddy opened 12 years ago

squiddy commented 12 years ago

Another developer had a problem with our project and we tracked it down to jingo's datetime filter.

The default format string is %B %e, %Y. It uses %e which is not available on all platforms (according to this list in the Python documentation). I guess replacing that by %d should be enough (although that adds a leading zero).

import datetime; x = datetime.datetime(2012, 12, 3, 12, 1, 34); x.strftime('%e') raises a ValueError exception, invalid format string.

>>> print platform.platform()
Windows-XP-5.1.2600-SP3
fwenzel commented 12 years ago

Hm you could submit a pull request and use a different format string if platform.system() is Windows?

jsocol commented 9 years ago

Going through old issues, I realized that I have no idea where %e came from in the first place. It's not in the Python docs. It's from strftime(3) on linux, and all it does is print a space-padded day instead of a zero-padded day (e.g. May 3, 2015 vs May 3, 2015 with %-d vs May 03, 2015 with %d).

Rather than platform/system branching, let's just use %-d, an actually documented python thing. I'll do that soon.