#178, #191 - improved regexps for dates matching - e.g. \d{1,2} changes to [0-3]*[0-9]

This commit is contained in:
SebastianMC 2025-01-14 17:57:17 +01:00
parent 4eb5d7c120
commit 2204982485
2 changed files with 23 additions and 7 deletions

View File

@ -10,14 +10,14 @@ export const NumberRegexStr: string = ' *(\\d+)'; // Plain number
export const CompoundNumberDotRegexStr: string = ' *(\\d+(?:\\.\\d+)*)'; // Compound number with dot as separator export const CompoundNumberDotRegexStr: string = ' *(\\d+(?:\\.\\d+)*)'; // Compound number with dot as separator
export const CompoundNumberDashRegexStr: string = ' *(\\d+(?:-\\d+)*)'; // Compound number with dash as separator export const CompoundNumberDashRegexStr: string = ' *(\\d+(?:-\\d+)*)'; // Compound number with dash as separator
export const Date_yyyy_mm_dd_RegexStr: string = ' *(\\d{4}-\\d{2}-\\d{2})' export const Date_yyyy_mm_dd_RegexStr: string = ' *(\\d{4}-[0-3]*[0-9]-[0-3]*[0-9])'
export const Date_yyyy_dd_mm_RegexStr: string = Date_yyyy_mm_dd_RegexStr export const Date_yyyy_dd_mm_RegexStr: string = Date_yyyy_mm_dd_RegexStr
export const Date_dd_Mmm_yyyy_RegexStr: string = ' *([0-3]*[0-9]-(?:Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)-\\d{4})'; // Date like 01-Jan-2020 export const Date_dd_Mmm_yyyy_RegexStr: string = ' *([0-3]*[0-9]-(?:Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)-\\d{4})'; // Date like 01-Jan-2020
export const Date_Mmm_dd_yyyy_RegexStr: string = ' *((?:Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)-[0-3]*[0-9]-\\d{4})'; // Date like Jan-01-2020 export const Date_Mmm_dd_yyyy_RegexStr: string = ' *((?:Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)-[0-3]*[0-9]-\\d{4})'; // Date like Jan-01-2020
export const Date_yyyy_Www_mm_dd_RegexStr: string = ' *(\\d{4}-W\\d{1,2} \\(\\d{2}-\\d{2}\\))' export const Date_yyyy_Www_mm_dd_RegexStr: string = ' *(\\d{4}-W[0-5]*[0-9] \\([0-3]*[0-9]-[0-3]*[0-9]\\))'
export const Date_yyyy_WwwISO_RegexStr: string = ' *(\\d{4}-W\\d{1,2})' export const Date_yyyy_WwwISO_RegexStr: string = ' *(\\d{4}-W[0-5]*[0-9])'
export const Date_yyyy_Www_RegexStr: string = Date_yyyy_WwwISO_RegexStr export const Date_yyyy_Www_RegexStr: string = Date_yyyy_WwwISO_RegexStr
export const DOT_SEPARATOR = '.' export const DOT_SEPARATOR = '.'

View File

@ -7,6 +7,8 @@ import {
convertPlainStringToRegex, convertPlainStringToRegex,
Date_dd_Mmm_yyyy_NormalizerFn, Date_dd_Mmm_yyyy_NormalizerFn,
Date_Mmm_dd_yyyy_NormalizerFn, Date_Mmm_dd_yyyy_NormalizerFn,
Date_yyyy_dd_mm_NormalizerFn,
Date_yyyy_mm_dd_NormalizerFn,
Date_yyyy_Www_mm_dd_NormalizerFn, Date_yyyy_Www_mm_dd_NormalizerFn,
Date_yyyy_Www_NormalizerFn, Date_yyyy_Www_NormalizerFn,
Date_yyyy_WwwISO_NormalizerFn, Date_yyyy_WwwISO_NormalizerFn,
@ -383,6 +385,8 @@ Here goes ASCII word \\a+
\\[yyyy-Www (mm-dd)] Week number ignored \\[yyyy-Www (mm-dd)] Week number ignored
Week number interpreted in ISO standard \\[yyyy-WwwISO] Week number interpreted in ISO standard \\[yyyy-WwwISO]
Week number interpreted in U.S. standard \\[yyyy-Www] Week number interpreted in U.S. standard \\[yyyy-Www]
\\[yyyy-mm-dd] plain spec 1
\\[yyyy-dd-mm] plain spec 2
` `
const expectedSortSpecsExampleSortingSymbols: { [key: string]: CustomSortSpec } = { const expectedSortSpecsExampleSortingSymbols: { [key: string]: CustomSortSpec } = {
@ -448,26 +452,38 @@ const expectedSortSpecsExampleSortingSymbols: { [key: string]: CustomSortSpec }
}, { }, {
type: CustomSortGroupType.ExactName, type: CustomSortGroupType.ExactName,
regexPrefix: { regexPrefix: {
regex: /^ *(\d{4}-W\d{1,2} \(\d{2}-\d{2}\)) Week number ignored$/i, regex: /^ *(\d{4}-W[0-5]*[0-9] \([0-3]*[0-9]-[0-3]*[0-9]\)) Week number ignored$/i,
normalizerFn: Date_yyyy_Www_mm_dd_NormalizerFn normalizerFn: Date_yyyy_Www_mm_dd_NormalizerFn
} }
}, { }, {
type: CustomSortGroupType.ExactName, type: CustomSortGroupType.ExactName,
regexPrefix: { regexPrefix: {
regex: /^Week number interpreted in ISO standard *(\d{4}-W\d{1,2})$/i, regex: /^Week number interpreted in ISO standard *(\d{4}-W[0-5]*[0-9])$/i,
normalizerFn: Date_yyyy_WwwISO_NormalizerFn normalizerFn: Date_yyyy_WwwISO_NormalizerFn
} }
}, { }, {
type: CustomSortGroupType.ExactName, type: CustomSortGroupType.ExactName,
regexPrefix: { regexPrefix: {
regex: /^Week number interpreted in U\.S\. standard *(\d{4}-W\d{1,2})$/i, regex: /^Week number interpreted in U\.S\. standard *(\d{4}-W[0-5]*[0-9])$/i,
normalizerFn: Date_yyyy_Www_NormalizerFn normalizerFn: Date_yyyy_Www_NormalizerFn
} }
}, {
type: CustomSortGroupType.ExactName,
regexPrefix: {
regex: /^ *(\d{4}-[0-3]*[0-9]-[0-3]*[0-9]) plain spec 1$/i,
normalizerFn: Date_yyyy_mm_dd_NormalizerFn
}
}, {
type: CustomSortGroupType.ExactName,
regexPrefix: {
regex: /^ *(\d{4}-[0-3]*[0-9]-[0-3]*[0-9]) plain spec 2$/i,
normalizerFn: Date_yyyy_dd_mm_NormalizerFn
}
}, { }, {
type: CustomSortGroupType.Outsiders type: CustomSortGroupType.Outsiders
}], }],
targetFoldersPaths: ['mock-folder'], targetFoldersPaths: ['mock-folder'],
outsidersGroupIdx: 12 outsidersGroupIdx: 14
} }
} }