diff options
author | Gerhard Weis <g.weis@uq.edu.au> | 2021-12-13 09:15:15 +1000 |
---|---|---|
committer | Gerhard Weis <g.weis@uq.edu.au> | 2021-12-13 09:15:15 +1000 |
commit | 924975890471f9baf3f0a86b277770fff299e106 (patch) | |
tree | 8854e9afbd4614d3b97d9d87aa71ad2b5212250e /src/isodate/isotime.py | |
parent | 6bebac0913c431a0406c7851e2d3356822b59baa (diff) | |
parent | 4f422ae415e8c9591677b97faf0776ece6d7afb8 (diff) | |
download | isodate-924975890471f9baf3f0a86b277770fff299e106.tar.gz |
Merge branch 'PR16'
* PR16:
Don't match garbage characters at the end of time strings
Don't match garbage characters at the end of date strings
Factor in some regexes
# Conflicts:
# src/isodate/isodates.py
# src/isodate/isotime.py
Diffstat (limited to 'src/isodate/isotime.py')
-rw-r--r-- | src/isodate/isotime.py | 47 |
1 files changed, 16 insertions, 31 deletions
diff --git a/src/isodate/isotime.py b/src/isodate/isotime.py index 182770b..3e2bb46 100644 --- a/src/isodate/isotime.py +++ b/src/isodate/isotime.py @@ -41,46 +41,31 @@ def build_time_regexps(): # +-hhmm # +-hh => # isotzinfo.TZ_REGEX + def add_re(regex_text): + TIME_REGEX_CACHE.append(re.compile(r"\A" + regex_text + TZ_REGEX + r"\Z")) + # 1. complete time: # hh:mm:ss.ss ... extended format - TIME_REGEX_CACHE.append( - re.compile( - r"T?(?P<hour>[0-9]{2}):" - r"(?P<minute>[0-9]{2}):" - r"(?P<second>[0-9]{2}" - r"([,.][0-9]+)?)" + TZ_REGEX - ) + add_re( + r"T?(?P<hour>[0-9]{2}):" + r"(?P<minute>[0-9]{2}):" + r"(?P<second>[0-9]{2}" + r"([,.][0-9]+)?)" ) # hhmmss.ss ... basic format - TIME_REGEX_CACHE.append( - re.compile( - r"T?(?P<hour>[0-9]{2})" - r"(?P<minute>[0-9]{2})" - r"(?P<second>[0-9]{2}" - r"([,.][0-9]+)?)" + TZ_REGEX - ) + add_re( + r"T?(?P<hour>[0-9]{2})" + r"(?P<minute>[0-9]{2})" + r"(?P<second>[0-9]{2}" + r"([,.][0-9]+)?)" ) # 2. reduced accuracy: # hh:mm.mm ... extended format - TIME_REGEX_CACHE.append( - re.compile( - r"T?(?P<hour>[0-9]{2}):" - r"(?P<minute>[0-9]{2}" - r"([,.][0-9]+)?)" + TZ_REGEX - ) - ) + add_re(r"T?(?P<hour>[0-9]{2}):" r"(?P<minute>[0-9]{2}" r"([,.][0-9]+)?)") # hhmm.mm ... basic format - TIME_REGEX_CACHE.append( - re.compile( - r"T?(?P<hour>[0-9]{2})" - r"(?P<minute>[0-9]{2}" - r"([,.][0-9]+)?)" + TZ_REGEX - ) - ) + add_re(r"T?(?P<hour>[0-9]{2})" r"(?P<minute>[0-9]{2}" r"([,.][0-9]+)?)") # hh.hh ... basic format - TIME_REGEX_CACHE.append( - re.compile(r"T?(?P<hour>[0-9]{2}" r"([,.][0-9]+)?)" + TZ_REGEX) - ) + add_re(r"T?(?P<hour>[0-9]{2}" r"([,.][0-9]+)?)") return TIME_REGEX_CACHE |