From 6e7b2e1b6a449afbe8ae1f8f48760f8729b45293 Mon Sep 17 00:00:00 2001 From: SebastianMC <23032356+SebastianMC@users.noreply.github.com> Date: Tue, 14 Jan 2025 21:48:52 +0100 Subject: [PATCH] #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+ --- src/custom-sort/matchers.ts | 6 ++-- src/test/int/dates-in-names.int.test.ts | 47 +++++++++++++++++++++++++ src/test/unit/matchers.spec.ts | 2 +- 3 files changed, 51 insertions(+), 4 deletions(-) diff --git a/src/custom-sort/matchers.ts b/src/custom-sort/matchers.ts index e10ec56..a48133e 100644 --- a/src/custom-sort/matchers.ts +++ b/src/custom-sort/matchers.ts @@ -24,11 +24,11 @@ export const DOT_SEPARATOR = '.' // ASCII 46 export const DASH_SEPARATOR = '-' 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 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) @@ -152,7 +152,7 @@ const YEAR_IDX = 1 const WEEK_IDX = 2 const MONTH_IDX = 3 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 JANUARY = 1 diff --git a/src/test/int/dates-in-names.int.test.ts b/src/test/int/dates-in-names.int.test.ts index 341dd85..b94a31d 100644 --- a/src/test/int/dates-in-names.int.test.ts +++ b/src/test/int/dates-in-names.int.test.ts @@ -236,6 +236,53 @@ describe('sortFolderItems', () => { "------.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 = 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", + ]) + }) }) diff --git a/src/test/unit/matchers.spec.ts b/src/test/unit/matchers.spec.ts index 339745f..7ef0ce4 100644 --- a/src/test/unit/matchers.spec.ts +++ b/src/test/unit/matchers.spec.ts @@ -467,7 +467,7 @@ describe('getNormalizedDate_yyyy_Www_NormalizerFn', () => { */ const params = [ ['2012-W1', '2011-12-26//'], - ['2012-W1+', '2012-01-01:/'], + ['2012-W1+', '2012-01-01>/'], ['2012-W1-', '2011-12-26./'], ]; it.each(params)('>%s< should become %s', (s: string, out: string) => {