Skip to content

Commit

Permalink
#178, #191 - improved regexps for dates matching - e.g. \d{1,2} chang…
Browse files Browse the repository at this point in the history
…es to [0-3]*[0-9]
  • Loading branch information
SebastianMC committed Jan 14, 2025
1 parent 4eb5d7c commit 2204982
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 7 deletions.
6 changes: 3 additions & 3 deletions src/custom-sort/matchers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 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_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_yyyy_Www_mm_dd_RegexStr: string = ' *(\\d{4}-W\\d{1,2} \\(\\d{2}-\\d{2}\\))'
export const Date_yyyy_WwwISO_RegexStr: string = ' *(\\d{4}-W\\d{1,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[0-5]*[0-9])'
export const Date_yyyy_Www_RegexStr: string = Date_yyyy_WwwISO_RegexStr

export const DOT_SEPARATOR = '.'
Expand Down
24 changes: 20 additions & 4 deletions src/test/unit/sorting-spec-processor.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import {
convertPlainStringToRegex,
Date_dd_Mmm_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_NormalizerFn,
Date_yyyy_WwwISO_NormalizerFn,
Expand Down Expand Up @@ -383,6 +385,8 @@ Here goes ASCII word \\a+
\\[yyyy-Www (mm-dd)] Week number ignored
Week number interpreted in ISO standard \\[yyyy-WwwISO]
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 } = {
Expand Down Expand Up @@ -448,26 +452,38 @@ const expectedSortSpecsExampleSortingSymbols: { [key: string]: CustomSortSpec }
}, {
type: CustomSortGroupType.ExactName,
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
}
}, {
type: CustomSortGroupType.ExactName,
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
}
}, {
type: CustomSortGroupType.ExactName,
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
}
}, {
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
}],
targetFoldersPaths: ['mock-folder'],
outsidersGroupIdx: 12
outsidersGroupIdx: 14
}
}

Expand Down

0 comments on commit 2204982

Please sign in to comment.