Skip to content

Instantly share code, notes, and snippets.

@zed
Last active August 29, 2015 14:07
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zed/11524fa26fa6882ad4d0 to your computer and use it in GitHub Desktop.
Save zed/11524fa26fa6882ad4d0 to your computer and use it in GitHub Desktop.
Parse human-readable dates in French
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
See
http://stackoverflow.com/questions/26294333/parse-french-date-in-python
"""
import parsedatetime as pdt
class pdtLocale_fr(pdt.pdt_locales.pdtLocale_icu):
def __init__(self):
super(pdtLocale_fr, self).__init__(localeID='fr_FR')
self.dayOffsets.update({u"aujourd'hui": 0, u'demain': 1, u'hier': -1})
pdt.pdtLocales['fr_FR'] = pdtLocale_fr
calendar = pdt.Calendar(pdt.Constants(localeID='fr_FR', usePyICU=False))
for date_string in [u"Aujourd'hui", "3 juillet", u"4 Août", u"Hier",
u"au jour de hui", u"aujour-d’hui",
u"au-jour-d’hui", "demain", "hier",
u"today", "tomorrow", "yesterday"]:
dt, rc = calendar.parseDT(date_string)
if rc > 0:
print(date_string, dt.date())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment