Commit 7a4166a2 authored by nmartensen's avatar nmartensen
Browse files

update timedelta regular expression, function and tests

--HG--
branch : 3.0
parent a686cd874ea0
......@@ -95,7 +95,7 @@ COLORS = r"\[(BLACK|BLUE|CYAN|GREEN|MAGENTA|RED|WHITE|YELLOW)\]"
LITERAL_GROUP = r'".*?"' # anything in quotes
LOCALE_GROUP = r'\[.+\]' # anything in square brackets, including colours
STRIP_RE = re.compile(f"{LITERAL_GROUP}|{LOCALE_GROUP}")
TIMEDELTA_RE = re.compile(r'\[hh?\](:mm(:ss(\.0*)?)?)?|\[mm?\]:ss(\.0*)?|\[ss?\](\.0*)?', re.I)
TIMEDELTA_RE = re.compile(r'\[hh?\](:mm(:ss(\.0*)?)?)?|\[mm?\](:ss(\.0*)?)?|\[ss?\](\.0*)?', re.I)
# Spec 18.8.31 numFmts
......@@ -112,7 +112,8 @@ def is_date_format(fmt):
def is_timedelta_format(fmt):
if fmt is None:
return False
return TIMEDELTA_RE.match(fmt) is not None
fmt = fmt.split(";")[0] # only look at the first format
return TIMEDELTA_RE.search(fmt) is not None
def is_datetime(fmt):
......
......@@ -103,9 +103,12 @@ def test_is_date_format(format, result):
('[ss]', True),
('[s].000', True),
('[ss].0', True),
('[m]', False),
('[mm]', False),
('[m]', True),
('[mm]', True),
('h:mm', False),
('[Blue]\+[h]:mm;[Red]\-[h]:mm;[h]:mm', True),
('[Blue]\+[h]:mm;[Red]\-[h]:mm;[Green][h]:mm', True),
('[h]:mm;[=0]\-', True),
]
)
def test_is_timedelta_format(format, result):
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment