1 from datetime import date
4 from .base import MetaValue
7 class DateValue(MetaValue):
9 def from_text(cls, text):
11 Dates for digitization of pictures. It seems we need the following:
14 half centuries/decades: '2 poł. XVIII w.', 'XVII w., l. 20'
16 circa 'ok. 1813-1814', 'ok.1876-ok.1886
19 For now we will translate this to some single date
20 losing information of course.
23 # check out the "N. poł X w." syntax
25 "(?:([12]) *poł[.]? +)?([MCDXVI]+) *w[.,]*(?: *l[.]? *([0-9]+))?"
27 vague_format = "(?:po *|ok. *)?([0-9]{4})(-[0-9]{2}-[0-9]{2})?"
29 m = re.match(century_format, text)
30 m2 = re.match(vague_format, text)
34 century = roman_to_int(m.group(2))
36 if decade is not None:
39 "Cannot specify both half and decade of century."
42 t = ((century*100 + (half-1)*50), 1, 1)
44 decade = int(decade or 0)
45 t = ((century*100 + decade), 1, 1)
50 t = time.strptime(year + mon_day, "%Y-%m-%d")
52 t = time.strptime(year, '%Y')
56 return cls(date(t[0], t[1], t[2]))
58 raise ValueError("Unrecognized date format. Try YYYY-MM-DD or YYYY.")