diff options
author | Gabriel <g2p.code@gmail.com> | 2015-01-20 17:59:19 +0100 |
---|---|---|
committer | Gabriel <g2p.code@gmail.com> | 2015-01-20 18:00:29 +0100 |
commit | 4f422ae415e8c9591677b97faf0776ece6d7afb8 (patch) | |
tree | ba4a088753bdbb09e0a0e18410ab572042dd6732 | |
parent | 2e68c720d50806b91b3d025eb5cbafd3a0957b44 (diff) | |
download | isodate-4f422ae415e8c9591677b97faf0776ece6d7afb8.tar.gz |
Don't match garbage characters at the end of time strings
Addresses #15.
-rw-r--r-- | src/isodate/isotime.py | 25 |
1 files changed, 12 insertions, 13 deletions
diff --git a/src/isodate/isotime.py b/src/isodate/isotime.py index 151a3f9..8b4d13c 100644 --- a/src/isodate/isotime.py +++ b/src/isodate/isotime.py @@ -67,26 +67,25 @@ def build_time_regexps(): # +-hhmm # +-hh => # isotzinfo.TZ_REGEX + def add_re(regex_text): + TIME_REGEX_CACHE.append( + re.compile('\A' + regex_text + TZ_REGEX + '\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}([,.][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}([,.][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}([,.][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}([,.][0-9]+)?)") # 2. reduced accuracy: # hh:mm.mm ... extended format # hhmm.mm ... basic format - TIME_REGEX_CACHE.append(re.compile(r"T?(?P<hour>[0-9]{2}):?" - r"(?P<minute>[0-9]{2}([,.][0-9]+)?)" - + TZ_REGEX)) + add_re(r"T?(?P<hour>[0-9]{2}):?" + r"(?P<minute>[0-9]{2}([,.][0-9]+)?)") # hh.hh ... basic format - TIME_REGEX_CACHE.append(re.compile(r"T?(?P<hour>[0-9]{2}([,.][0-9]+)?)" - + TZ_REGEX)) + add_re(r"T?(?P<hour>[0-9]{2}([,.][0-9]+)?)") return TIME_REGEX_CACHE |