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]