MatchesXsDate🔗

Type: Pattern verification
Check that text conforms to the pattern of an xs:date.
text🔗
Text to be checked
Return🔗
True if the text conforms to the pattern

Code

digit = "[0-9]"
year_frag = f"-?(([1-9]{digit}{digit}{digit}+)|(0{digit}{digit}{digit}))"
month_frag = f"((0[1-9])|(1[0-2]))"
day_frag = f"((0[1-9])|([12]{digit})|(3[01]))"
minute_frag = f"[0-5]{digit}"
timezone_frag = rf"(Z|(\+|-)(0{digit}|1[0-3]):{minute_frag}|14:00)"
date_lexical_rep = f"{year_frag}-{month_frag}-{day_frag}{timezone_frag}?"

pattern = f"^{date_lexical_rep}$"
return match(pattern, text) is not None