#178 - explicit support for telling if the Www date should be same, earlier than the first day of the week or later than the last day of the week
- syntax W1 W1- W1+
This commit is contained in:
parent
f7c69b18f9
commit
6e7b2e1b6a
|
@ -24,11 +24,11 @@ export const DOT_SEPARATOR = '.' // ASCII 46
|
||||||
export const DASH_SEPARATOR = '-'
|
export const DASH_SEPARATOR = '-'
|
||||||
|
|
||||||
const SLASH_SEPARATOR = '/' // ASCII 47, right before ASCII 48 = '0'
|
const SLASH_SEPARATOR = '/' // ASCII 47, right before ASCII 48 = '0'
|
||||||
const COLON_SEPARATOR = ':' // ASCII 58, first non-digit character
|
const GT_SEPARATOR = '>' // ASCII 62, alphabetical sorting in Collator puts it after /
|
||||||
const PIPE_SEPARATOR = '|' // ASCII 124
|
const PIPE_SEPARATOR = '|' // ASCII 124
|
||||||
|
|
||||||
const EARLIER_THAN_SLASH_SEPARATOR = DOT_SEPARATOR
|
const EARLIER_THAN_SLASH_SEPARATOR = DOT_SEPARATOR
|
||||||
const LATER_THAN_SLASH_SEPARATOR = COLON_SEPARATOR
|
const LATER_THAN_SLASH_SEPARATOR = GT_SEPARATOR
|
||||||
|
|
||||||
export const DEFAULT_NORMALIZATION_PLACES = 8; // Fixed width of a normalized number (with leading zeros)
|
export const DEFAULT_NORMALIZATION_PLACES = 8; // Fixed width of a normalized number (with leading zeros)
|
||||||
|
|
||||||
|
@ -152,7 +152,7 @@ const YEAR_IDX = 1
|
||||||
const WEEK_IDX = 2
|
const WEEK_IDX = 2
|
||||||
const MONTH_IDX = 3
|
const MONTH_IDX = 3
|
||||||
const DAY_IDX = 4
|
const DAY_IDX = 4
|
||||||
const RELATIVE_ORDER_IDX = 3 // For the yyyy-Www only: yyyy-Www> or yyyy-Www<
|
const RELATIVE_ORDER_IDX = 3 // For the yyyy-Www only: yyyy-Www- or yyyy-Www+
|
||||||
|
|
||||||
const DECEMBER = 12
|
const DECEMBER = 12
|
||||||
const JANUARY = 1
|
const JANUARY = 1
|
||||||
|
|
|
@ -236,6 +236,53 @@ describe('sortFolderItems', () => {
|
||||||
"------.md"
|
"------.md"
|
||||||
])
|
])
|
||||||
})
|
})
|
||||||
|
it('should correctly order the week number with specifiers', () => {
|
||||||
|
// given
|
||||||
|
const processor: SortingSpecProcessor = new SortingSpecProcessor()
|
||||||
|
const sortSpecTxt =
|
||||||
|
`
|
||||||
|
/+ \\[yyyy-Www]
|
||||||
|
/+ \\[yyyy-mm-dd]
|
||||||
|
> a-z
|
||||||
|
`
|
||||||
|
const PARENT_PATH = 'parent/folder/path'
|
||||||
|
const sortSpecsCollection = processor.parseSortSpecFromText(
|
||||||
|
sortSpecTxt.split('\n'),
|
||||||
|
PARENT_PATH,
|
||||||
|
'file name with the sorting, irrelevant here'
|
||||||
|
)
|
||||||
|
|
||||||
|
const folder: TFolder = mockTFolder(PARENT_PATH,[
|
||||||
|
// ISO and U.S. standard for 2025 give the same week numbers (remark for clarity)
|
||||||
|
mockTFile('2025-03-09', 'md'), // sunday of W10
|
||||||
|
mockTFile('2025-W11-', 'md'), // earlier than monday of W11
|
||||||
|
mockTFile('2025-03-10', 'md'), // monday W11
|
||||||
|
mockTFile('2025-W11', 'md'), // monday of W11
|
||||||
|
mockTFile('2025-03-16', 'md'), // sunday W11
|
||||||
|
mockTFile('2025-W11+', 'md'), // later than sunday W11 // expected
|
||||||
|
mockTFile('2025-03-17', 'md'), // monday of W12
|
||||||
|
])
|
||||||
|
|
||||||
|
const sortSpec: CustomSortSpec = sortSpecsCollection?.sortSpecByPath![PARENT_PATH]!
|
||||||
|
|
||||||
|
const ctx: ProcessingContext = {}
|
||||||
|
|
||||||
|
// when
|
||||||
|
const result: Array<TAbstractFile> = sortFolderItems(folder, folder.children, sortSpec, ctx, OS_alphabetical)
|
||||||
|
|
||||||
|
// then
|
||||||
|
// U.S. standard of weeks numbering
|
||||||
|
const orderedNames = result.map(f => f.name)
|
||||||
|
expect(orderedNames).toEqual([
|
||||||
|
"2025-03-17.md",
|
||||||
|
'2025-W11+.md',
|
||||||
|
"2025-03-16.md",
|
||||||
|
'2025-W11.md',
|
||||||
|
"2025-03-10.md",
|
||||||
|
"2025-W11-.md",
|
||||||
|
"2025-03-09.md",
|
||||||
|
])
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -467,7 +467,7 @@ describe('getNormalizedDate_yyyy_Www_NormalizerFn', () => {
|
||||||
*/
|
*/
|
||||||
const params = [
|
const params = [
|
||||||
['2012-W1', '2011-12-26//'],
|
['2012-W1', '2011-12-26//'],
|
||||||
['2012-W1+', '2012-01-01:/'],
|
['2012-W1+', '2012-01-01>/'],
|
||||||
['2012-W1-', '2011-12-26./'],
|
['2012-W1-', '2011-12-26./'],
|
||||||
];
|
];
|
||||||
it.each(params)('>%s< should become %s', (s: string, out: string) => {
|
it.each(params)('>%s< should become %s', (s: string, out: string) => {
|
||||||
|
|
Loading…
Reference in New Issue