Skip to content

Commit

Permalink
Warn about invalid months/days
Browse files Browse the repository at this point in the history
Instead of fixing the regexes, just let dateutil take care of it

See #2070 (comment)
  • Loading branch information
Famlam authored and frodrigo committed Nov 18, 2023
1 parent 11bb297 commit e06a767
Showing 1 changed file with 2 additions and 9 deletions.
11 changes: 2 additions & 9 deletions plugins/Date.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,6 @@ def init(self, logger):
"mhs:inscription_date", # Heritage
]
self.default_date = datetime.datetime(9999, 12, 1)
self.Year = re.compile(u"^[12][0-9][0-9][0-9]$")
self.Day1 = re.compile(u"^[12][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]$")
self.Day2 = re.compile(u"^[0-9][0-9]/[0-9][0-9]/[12][0-9][0-9][0-9]$")
self.Aprox = re.compile(u"^(?:early|mid|late|before|after|spring|summer|autumn|winter) [^ ]+")

def convert2date(self, string):
Expand All @@ -64,10 +61,6 @@ def check(self, string):
return len(string) > 1 and self.check(string[:-1])
if string[-3:] == ' BC' or string[-3:] == ' AD':
return len(string) > 3 and self.check(string[:-3])
if len(string) == 4 and self.Year.match(string):
return True
if len(string) == 10 and (self.Day1.match(string) or self.Day2.match(string)):
return True
if string[0] == 'C':
try:
int(string[1:])
Expand Down Expand Up @@ -106,12 +99,12 @@ class Test(TestPluginCommon):
def test(self):
a = Date(None)
a.init(None)
for d in ["~1855", "~1940s", "~C13", "C18", "1970s", "1914", "1914..1918", "2008-08-08..2008-08-24", "late 1920s", "after 1500", "summer 1998", "480 BC", "2012-10", "2002-11", "2014", "2010.."]:
for d in ["~1855", "~1940s", "~C13", "C18", "1970s", "1914", "1914..1918", "2008-08-08..2008-08-24", "late 1920s", "after 1500", "summer 1998", "480 BC", "2012-10", "2002-11", "2014", "2010..", "2022-04-08"]:
assert not a.node(None, {"date":d}), ("date={0}".format(d))

assert not a.node(None, {"date":"yes", "amenity":"clock"}), ("date=yes")

for d in ["yes", "XVI", "p", "0000", "9999", "Ca9", "1914..9999", "2014..Ca09", "7000", "~"]:
for d in ["yes", "XVI", "p", "0000", "9999", "Ca9", "1914..9999", "2014..Ca09", "7000", "~", "2022-88", "2022-12-99", "2022-99-12"]:
self.check_err(a.node(None, {"date":d}), ("date={0}".format(d)))
self.check_err(a.way(None, {"date":d}, None), ("date={0}".format(d)))
self.check_err(a.relation(None, {"date":d}, None), ("date={0}".format(d)))

0 comments on commit e06a767

Please sign in to comment.