Commit 8e386d77 authored by nmartensen's avatar nmartensen
Browse files

improve datetime format detection

--HG--
branch : 3.0
parent 32c38cb55130
......@@ -93,7 +93,7 @@ FORMAT_CURRENCY_EUR_SIMPLE = '[$EUR ]#,##0.00_-'
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
LOCALE_GROUP = r'\[(?!hh?\]|mm?\]|ss?\])[^\]]*\]' # anything in square brackets, except hours or minutes or seconds
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)
......
......@@ -77,6 +77,16 @@ def test_strip_quotes(fmt, stripped):
(r"0_ ;[Red]\-0\ ", False),
(r"\Y000000", False),
(r'#,##0.0####" YMD"', False),
('[h]', True),
('[ss]', True),
('[s].000', True),
('[m]', True),
('[mm]', True),
('[Blue]\+[h]:mm;[Red]\-[h]:mm;[Green][h]:mm', True),
('[>=100][Magenta][s].00', True),
('[h]:mm;[=0]\-', True),
('[>=100][Magenta].00', False),
('[>=100][Magenta]General', False),
]
)
def test_is_date_format(format, result):
......@@ -108,7 +118,10 @@ def test_is_date_format(format, result):
('h:mm', False),
('[Blue]\+[h]:mm;[Red]\-[h]:mm;[h]:mm', True),
('[Blue]\+[h]:mm;[Red]\-[h]:mm;[Green][h]:mm', True),
('[>=100][Magenta][s].00', True),
('[h]:mm;[=0]\-', True),
('[>=100][Magenta].00', False),
('[>=100][Magenta]General', False),
]
)
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