ilyesdata / parsedatetime

Automatically exported from code.google.com/p/parsedatetime
Apache License 2.0
0 stars 0 forks source link

Unable to parse date "Sept 23 1942" #45

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
I'm trying to parse a date structured like "Sept 23 1942". PDT fails to parse 
it properly:

>>> from parsedatetime import parsedatetime, parsedatetime_consts
>>> pdt = parsedatetime.Calendar(parsedatetime_consts.Constants())
>>> pdt.parse('Sept 23 1942')
((2012, 9, 1, 19, 42, 0, 4, 55, 0), 3)

It works if I expand "Sept" to "September". I'm currently expanding all short 
months into long moths, but that doesn't seem elegant.

Any ideas as to why this is happening?

Original issue reported on code.google.com by i.nnikishi on 24 Feb 2012 at 11:58

GoogleCodeExporter commented 8 years ago
I looked at the source code for PDT and it seems like only three-letter-long 
abbreviated month names are handled.

Is there any way to add more month names (possibly nested lists to group the 
different possible names for each month into one)?

Original comment by i.nnikishi on 25 Feb 2012 at 12:20

GoogleCodeExporter commented 8 years ago
yep, short months are handled by the locale class and are normally only 3 
character months - to add other strings you would need to change line 1720 of 
parsedatetime/__init__.py 

    self.locale.re_values['shortmonths'] = '%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s' % smth

so that the list that is assigned has more months and then adjust the %s| 
pattern to hold the extra

Original comment by bear42 on 25 Feb 2012 at 4:16