Skip to content

Commit 6e7b2e1

Browse files
committed
#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+
1 parent f7c69b1 commit 6e7b2e1

File tree

3 files changed

+51
-4
lines changed

3 files changed

+51
-4
lines changed

src/custom-sort/matchers.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@ export const DOT_SEPARATOR = '.' // ASCII 46
2424
export const DASH_SEPARATOR = '-'
2525

2626
const SLASH_SEPARATOR = '/' // ASCII 47, right before ASCII 48 = '0'
27-
const COLON_SEPARATOR = ':' // ASCII 58, first non-digit character
27+
const GT_SEPARATOR = '>' // ASCII 62, alphabetical sorting in Collator puts it after /
2828
const PIPE_SEPARATOR = '|' // ASCII 124
2929

3030
const EARLIER_THAN_SLASH_SEPARATOR = DOT_SEPARATOR
31-
const LATER_THAN_SLASH_SEPARATOR = COLON_SEPARATOR
31+
const LATER_THAN_SLASH_SEPARATOR = GT_SEPARATOR
3232

3333
export const DEFAULT_NORMALIZATION_PLACES = 8; // Fixed width of a normalized number (with leading zeros)
3434

@@ -152,7 +152,7 @@ const YEAR_IDX = 1
152152
const WEEK_IDX = 2
153153
const MONTH_IDX = 3
154154
const DAY_IDX = 4
155-
const RELATIVE_ORDER_IDX = 3 // For the yyyy-Www only: yyyy-Www> or yyyy-Www<
155+
const RELATIVE_ORDER_IDX = 3 // For the yyyy-Www only: yyyy-Www- or yyyy-Www+
156156

157157
const DECEMBER = 12
158158
const JANUARY = 1

src/test/int/dates-in-names.int.test.ts

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,53 @@ describe('sortFolderItems', () => {
236236
"------.md"
237237
])
238238
})
239+
it('should correctly order the week number with specifiers', () => {
240+
// given
241+
const processor: SortingSpecProcessor = new SortingSpecProcessor()
242+
const sortSpecTxt =
243+
`
244+
/+ \\[yyyy-Www]
245+
/+ \\[yyyy-mm-dd]
246+
> a-z
247+
`
248+
const PARENT_PATH = 'parent/folder/path'
249+
const sortSpecsCollection = processor.parseSortSpecFromText(
250+
sortSpecTxt.split('\n'),
251+
PARENT_PATH,
252+
'file name with the sorting, irrelevant here'
253+
)
254+
255+
const folder: TFolder = mockTFolder(PARENT_PATH,[
256+
// ISO and U.S. standard for 2025 give the same week numbers (remark for clarity)
257+
mockTFile('2025-03-09', 'md'), // sunday of W10
258+
mockTFile('2025-W11-', 'md'), // earlier than monday of W11
259+
mockTFile('2025-03-10', 'md'), // monday W11
260+
mockTFile('2025-W11', 'md'), // monday of W11
261+
mockTFile('2025-03-16', 'md'), // sunday W11
262+
mockTFile('2025-W11+', 'md'), // later than sunday W11 // expected
263+
mockTFile('2025-03-17', 'md'), // monday of W12
264+
])
265+
266+
const sortSpec: CustomSortSpec = sortSpecsCollection?.sortSpecByPath![PARENT_PATH]!
267+
268+
const ctx: ProcessingContext = {}
269+
270+
// when
271+
const result: Array<TAbstractFile> = sortFolderItems(folder, folder.children, sortSpec, ctx, OS_alphabetical)
272+
273+
// then
274+
// U.S. standard of weeks numbering
275+
const orderedNames = result.map(f => f.name)
276+
expect(orderedNames).toEqual([
277+
"2025-03-17.md",
278+
'2025-W11+.md',
279+
"2025-03-16.md",
280+
'2025-W11.md',
281+
"2025-03-10.md",
282+
"2025-W11-.md",
283+
"2025-03-09.md",
284+
])
285+
})
239286
})
240287

241288

src/test/unit/matchers.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,7 @@ describe('getNormalizedDate_yyyy_Www_NormalizerFn', () => {
467467
*/
468468
const params = [
469469
['2012-W1', '2011-12-26//'],
470-
['2012-W1+', '2012-01-01:/'],
470+
['2012-W1+', '2012-01-01>/'],
471471
['2012-W1-', '2011-12-26./'],
472472
];
473473
it.each(params)('>%s< should become %s', (s: string, out: string) => {

0 commit comments

Comments
 (0)