diff options
author | Gabriel <g2p.code@gmail.com> | 2015-01-20 17:44:02 +0100 |
---|---|---|
committer | Gabriel <g2p.code@gmail.com> | 2015-01-20 17:59:48 +0100 |
commit | b9917aff3319ec112cf59c1f5ca84fa1bd3a7538 (patch) | |
tree | 2740757215a31fc3c6e6244e31fcce98277d6e44 | |
parent | af2f62b43e89f6c80faf34fbc23892d2b91255c6 (diff) | |
download | isodate-b9917aff3319ec112cf59c1f5ca84fa1bd3a7538.tar.gz |
Factor in some regexes
This is for date and time formats that differed in a single
optional character.
-rw-r--r-- | src/isodate/isodates.py | 12 | ||||
-rw-r--r-- | src/isodate/isotime.py | 5 |
2 files changed, 4 insertions, 13 deletions
diff --git a/src/isodate/isodates.py b/src/isodate/isodates.py index 37d42f8..6660245 100644 --- a/src/isodate/isodates.py +++ b/src/isodate/isodates.py @@ -87,21 +87,15 @@ def build_date_regexps(yeardigits=4, expanded=False): % (sign, yeardigits))) # 3. ordinal dates: # YYYY-DDD or +-YYYYYY-DDD ... extended format - cache_entry.append(re.compile(r"(?P<sign>[+-]){%d}(?P<year>[0-9]{%d})" - r"-(?P<day>[0-9]{3})" - % (sign, yeardigits))) # YYYYDDD or +-YYYYYYDDD ... basic format cache_entry.append(re.compile(r"(?P<sign>[+-]){%d}(?P<year>[0-9]{%d})" - r"(?P<day>[0-9]{3})" + r"-?(?P<day>[0-9]{3})" % (sign, yeardigits))) # 4. week dates: # YYYY-Www or +-YYYYYY-Www ... extended reduced accuracy week date - cache_entry.append(re.compile(r"(?P<sign>[+-]){%d}(?P<year>[0-9]{%d})" - r"-W(?P<week>[0-9]{2})" - % (sign, yeardigits))) # YYYYWww or +-YYYYYYWww ... basic reduced accuracy week date - cache_entry.append(re.compile(r"(?P<sign>[+-]){%d}(?P<year>[0-9]{%d})W" - r"(?P<week>[0-9]{2})" + cache_entry.append(re.compile(r"(?P<sign>[+-]){%d}(?P<year>[0-9]{%d})" + r"-?W(?P<week>[0-9]{2})" % (sign, yeardigits))) # 5. month dates: # YYY-MM or +-YYYYYY-MM ... reduced accuracy specific month diff --git a/src/isodate/isotime.py b/src/isodate/isotime.py index 2b268d0..151a3f9 100644 --- a/src/isodate/isotime.py +++ b/src/isodate/isotime.py @@ -80,11 +80,8 @@ def build_time_regexps(): + TZ_REGEX)) # 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}([,.][0-9]+)?)" - + TZ_REGEX)) # hhmm.mm ... basic format - TIME_REGEX_CACHE.append(re.compile(r"T?(?P<hour>[0-9]{2})" + TIME_REGEX_CACHE.append(re.compile(r"T?(?P<hour>[0-9]{2}):?" r"(?P<minute>[0-9]{2}([,.][0-9]+)?)" + TZ_REGEX)) # hh.hh ... basic format |