@staticmethod<EOL><INDENT>def to_datetime(date_key):<DEDENT>
match = re.search(r'<STR_LIT>', date_key)<EOL>formatter = '<STR_LIT>'<EOL>if len(match.group()) == <NUM_LIT:10>:<EOL><INDENT>formatter += '<STR_LIT>'<EOL><DEDENT>return datetime.strptime(<EOL>match.group(), formatter).replace(tzinfo=pytz.UTC)<EOL>
Extract the first date from 'key' matching YYYY-MM-DD
or YYYY-MM, and convert to datetime.