Skip to content

Commit

Permalink
Merge 4f422ae into af2f62b
Browse files Browse the repository at this point in the history
  • Loading branch information
g2p committed Jan 20, 2015
2 parents af2f62b + 4f422ae commit 5926a17
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 48 deletions.
60 changes: 28 additions & 32 deletions src/isodate/isodates.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,56 +67,52 @@ def build_date_regexps(yeardigits=4, expanded=False):
sign = 1
else:
sign = 0
def add_re(regex_text):
cache_entry.append(re.compile('\A' + regex_text + '\Z'))
# 1. complete dates:
# YYYY-MM-DD or +- YYYYYY-MM-DD... extended date format
cache_entry.append(re.compile(r"(?P<sign>[+-]){%d}(?P<year>[0-9]{%d})"
r"-(?P<month>[0-9]{2})-(?P<day>[0-9]{2})"
% (sign, yeardigits)))
add_re(r"(?P<sign>[+-]){%d}(?P<year>[0-9]{%d})"
r"-(?P<month>[0-9]{2})-(?P<day>[0-9]{2})"
% (sign, yeardigits))
# YYYYMMDD or +- YYYYYYMMDD... basic date format
cache_entry.append(re.compile(r"(?P<sign>[+-]){%d}(?P<year>[0-9]{%d})"
r"(?P<month>[0-9]{2})(?P<day>[0-9]{2})"
% (sign, yeardigits)))
add_re(r"(?P<sign>[+-]){%d}(?P<year>[0-9]{%d})"
r"(?P<month>[0-9]{2})(?P<day>[0-9]{2})"
% (sign, yeardigits))
# 2. complete week dates:
# YYYY-Www-D or +-YYYYYY-Www-D ... extended week date
cache_entry.append(re.compile(r"(?P<sign>[+-]){%d}(?P<year>[0-9]{%d})"
r"-W(?P<week>[0-9]{2})-(?P<day>[0-9]{1})"
% (sign, yeardigits)))
add_re(r"(?P<sign>[+-]){%d}(?P<year>[0-9]{%d})"
r"-W(?P<week>[0-9]{2})-(?P<day>[0-9]{1})"
% (sign, yeardigits))
# YYYYWwwD or +-YYYYYYWwwD ... basic week date
cache_entry.append(re.compile(r"(?P<sign>[+-]){%d}(?P<year>[0-9]{%d})W"
r"(?P<week>[0-9]{2})(?P<day>[0-9]{1})"
% (sign, yeardigits)))
add_re(r"(?P<sign>[+-]){%d}(?P<year>[0-9]{%d})W"
r"(?P<week>[0-9]{2})(?P<day>[0-9]{1})"
% (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})"
% (sign, yeardigits)))
add_re(r"(?P<sign>[+-]){%d}(?P<year>[0-9]{%d})"
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})"
% (sign, yeardigits)))
add_re(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
cache_entry.append(re.compile(r"(?P<sign>[+-]){%d}(?P<year>[0-9]{%d})"
r"-(?P<month>[0-9]{2})"
% (sign, yeardigits)))
add_re(r"(?P<sign>[+-]){%d}(?P<year>[0-9]{%d})"
r"-(?P<month>[0-9]{2})"
% (sign, yeardigits))
# 6. year dates:
# YYYY or +-YYYYYY ... reduced accuracy specific year
cache_entry.append(re.compile(r"(?P<sign>[+-]){%d}(?P<year>[0-9]{%d})"
% (sign, yeardigits)))
add_re(r"(?P<sign>[+-]){%d}(?P<year>[0-9]{%d})"
% (sign, yeardigits))
# 7. century dates:
# YY or +-YYYY ... reduced accuracy specific century
cache_entry.append(re.compile(r"(?P<sign>[+-]){%d}"
r"(?P<century>[0-9]{%d})"
% (sign, yeardigits - 2)))
add_re(r"(?P<sign>[+-]){%d}"
r"(?P<century>[0-9]{%d})"
% (sign, yeardigits - 2))

DATE_REGEX_CACHE[(yeardigits, expanded)] = cache_entry
return DATE_REGEX_CACHE[(yeardigits, expanded)]
Expand Down
28 changes: 12 additions & 16 deletions src/isodate/isotime.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,29 +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
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})"
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


Expand Down

0 comments on commit 5926a17

Please sign in to comment.