Skip to content
This repository has been archived by the owner on Nov 29, 2022. It is now read-only.

Commit

Permalink
Added DD/MM/YY and MM/DD/YY to default date rule
Browse files Browse the repository at this point in the history
  • Loading branch information
hSaria committed May 30, 2022
1 parent 64be64f commit 28f68bc
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
4 changes: 3 additions & 1 deletion chromaterm/default_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,9 @@

RULE_DATE = Rule(
r'''(?ix)\b(
(\d{2}|\d{4})\-(0?[1-9]|1[0-2])\-(3[0-1]|[1-2]\d|0?[1-9])| # YYYY-MM-DD, YY-MM-DD
(\d{2}|\d{4})(?P<sep1>[-/])(0?[1-9]|1[0-2])(?P=sep1)(3[0-1]|[1-2]\d|0?[1-9])| # YYYY-MM-DD, YY-MM-DD, YYYY/MM/DD, YY/MM/DD
(3[0-1]|[1-2]\d|0?[1-9])(?P<sep2>[-/])(0?[1-9]|1[0-2])(?P=sep2)(\d{2}|\d{4})| # DD-MM-YYYY, DD-MM-YY, DD/MM/YYYY, DD/MM/YY
(0?[1-9]|1[0-2])(?P<sep3>[-/])(3[0-1]|[1-2]\d|0?[1-9])(?P=sep3)(\d{2}|\d{4})| # MM-DD-YYYY, MM-DD-YY, MM/DD/YYYY, MM/DD/YY
(jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec)\s+( # MMM
(3[0-1]|[1-2]\d|0?[1-9])(\s+\d{4})?|\d{4} # DD (YYYY)?, YYYY
)|(3[0-1]|[1-2]\d|0?[1-9])\s(jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec)(?!\s+(3[0-1]|[1-2]\d|0?[1-9])([^\w:]|$))(\s+\d{4})? # DD MMM (YYYY)?
Expand Down
12 changes: 7 additions & 5 deletions tests/test_default_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,13 +122,15 @@ def test_rule_size(pcre):
def test_rule_date(pcre):
'''Default rule: Date.'''
positives = [
'2019-12-31', '2019-12-31', 'jan 2019', 'feb 2019', 'Mar 2019',
'apr 2019', 'MAY 2019', 'Jun 2019', 'jul 2019', 'AUG 19', 'sep 20',
'oct 21', 'dec 23', 'AUG 19 2021', '24 jan', '25 feb 2019'
'2019-12-31', '2019-12-31', '2019/12/31', '12/31/2019', '31/12/2019',
'31/12/19', '31-12-19', 'jan 2019', 'feb 2019', 'Mar 2019', 'apr 2019',
'MAY 2019', 'Jun 2019', 'jul 2019', 'AUG 19', 'sep 20', 'oct 21',
'dec 23', 'AUG 19 2021', '24 jan', '25 feb 2019'
]
negatives = [
'201-12-31', '2019-13-31', '2019-12-32', 'xyz 2019', 'Jun 201',
'xyz 26', 'jun 32', '32 jun'
'201-12-31', '2019-13-31', '2019-12-32', '2019-12/31', '2019/12-31',
'12-31/2019', '12/31-2019', 'xyz 2019', 'Jun 201', 'xyz 26', 'jun 32',
'32 jun'
]
rule = chromaterm.default_config.RULE_DATE
rule.pcre = pcre
Expand Down

0 comments on commit 28f68bc

Please sign in to comment.