Skip to content

Commit 8bf6d5e

Browse files
committed
Fix duration unit tests
1 parent 9425507 commit 8bf6d5e

File tree

2 files changed

+9
-14
lines changed

2 files changed

+9
-14
lines changed

klp.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -849,9 +849,10 @@ def extraction_function(s):
849849
return None
850850

851851
doc = {
852+
"duration": "duration",
852853
"email": "email address",
853854
"fqdn": "fully qualified domain name (FQDN)",
854-
"function": "function calls",
855+
"function": "function call",
855856
"gitcommit": "git commit hash",
856857
"hexnum": "hex number with 0x prefix",
857858
"hexcolor": "hex color code",
@@ -5265,8 +5266,9 @@ def get_patterns_for_level(level: str) -> Dict[str, str]:
52655266
"version", # Version strings starting with v/V
52665267
]
52675268
maximum = default + [
5268-
"hexnum", # place this before "number", because it's more specific
5269-
"num", # place this before default not to mess with <ipv4>
5269+
"hexnum",
5270+
"duration",
5271+
"num", # place this last, because it's least specific
52705272
]
52715273
patterns = {
52725274
"min": minimum,

tests/test_duration_regex.py

+4-11
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,9 @@
11
import re
22

3-
# Duration patterns with stricter boundaries.
4-
DURATION_PATTERNS = [
5-
# Basic and decimal with units (common short forms)
6-
r"(?<![A-Za-z0-9.])(?:\d+(?:\.\d+)?)(?:us|ms|[smh])(?![A-Za-z0-9.])",
7-
# Written out units, including longer time spans
8-
r"(?<![A-Za-z0-9.])(?:\d+(?:\.\d+)?)(?:\s*(?:microsecond|millisecond|second|minute|hour|day|week|month|year)s?)(?![A-Za-z0-9.])",
9-
# Microseconds with μ
10-
r"(?<![A-Za-z0-9.])(?:\d+(?:\.\d+)?)(?:μs|µs)(?![A-Za-z0-9.])",
11-
# Combined units (2 or 3 parts) like 1h30m or 1h30m15s
12-
r"(?<![A-Za-z0-9.])(?:\d+h\d+m\d+s|\d+h\d+m|\d+h\d+s|\d+m\d+s)(?![A-Za-z0-9.])",
13-
]
3+
from klp import BUILTIN_REGEXES
4+
5+
6+
DURATION_PATTERNS = BUILTIN_REGEXES["duration"]
147

158

169
def is_duration(text: str) -> bool:

0 commit comments

Comments
 (0)