# HG changeset patch # User Ludovic Chabant # Date 1438185521 25200 # Node ID 63ae5eae90ca9ac1c5dac2763ab8594382425c39 # Parent 1f37f66204b804ddfc686eb7155a66569ba98462 templating: Add `now` global to Jinja, improve date error message. diff -r 1f37f66204b8 -r 63ae5eae90ca piecrust/templating/jinjaengine.py --- a/piecrust/templating/jinjaengine.py Tue Jul 28 23:56:09 2015 -0700 +++ b/piecrust/templating/jinjaengine.py Wed Jul 29 08:58:41 2015 -0700 @@ -205,6 +205,7 @@ # Now add globals and filters. self.globals.update({ + 'now': get_now_date(), 'fail': raise_exception, 'highlight_css': get_highlight_css}) @@ -317,6 +318,10 @@ return email.utils.formatdate(value, localtime=localtime) +def get_now_date(): + return time.time() + + def get_date(value, fmt): if value == 'now': value = time.time() @@ -328,12 +333,13 @@ else: suggest_message = ("We can't suggest a proper date format " "for you right now, though.") - raise Exception("PieCrust 1 date formats won't work in PieCrust 2. " + raise Exception("Got incorrect date format: '%s\n" + "PieCrust 1 date formats won't work in PieCrust 2. " "%s\n" "Please check the `strftime` formatting page here: " "https://docs.python.org/3/library/datetime.html" "#strftime-and-strptime-behavior" % - suggest_message) + (fmt, suggest_message)) return time.strftime(fmt, time.localtime(value))