From 481272ac226efd926562457ca7de6f68195e6359 Mon Sep 17 00:00:00 2001 From: Jerome Petazzoni Date: Fri, 27 Jul 2018 06:07:11 -0500 Subject: [PATCH] Add fallback when non-standard strftime is not supported Closes #301 Thanks @petertang2012 --- slides/index.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/slides/index.py b/slides/index.py index 2c4bf9e8..d9cda3cc 100755 --- a/slides/index.py +++ b/slides/index.py @@ -113,7 +113,13 @@ for item in items: 1: "st", 2: "nd", 3: "rd", 21: "st", 22: "nd", 23: "rd", 31: "st"}.get(date.day, "th") - item["prettydate"] = date.strftime("%B %e{}, %Y").format(suffix) + # %e is a non-standard extension (it displays the day, but without a + # leading zero). If strftime fails with ValueError, try to fall back + # on %d (which displays the day but with a leading zero when needed). + try: + item["prettydate"] = date.strftime("%B %e{}, %Y").format(suffix) + except ValueError: + item["prettydate"] = date.strftime("%B %d{}, %Y").format(suffix) today = datetime.date.today() coming_soon = [i for i in items if i.get("date") and i["date"] >= today]