From 3dd4acee6fe23fb64c5934acc1b4c2138b680f56 Mon Sep 17 00:00:00 2001 From: vycdev2 Date: Fri, 18 Sep 2026 04:05:07 +0000 Subject: [PATCH] fix: apply configured day length to larger durations --- CHANGELOG.md | 1 + src/utils/time.ts | 17 +++++++++-------- test/time.spec.ts | 12 ++++++++++++ 3 files changed, 22 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6af930d..4983b3b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -49,6 +49,7 @@ - Replaced Moment with the `moment-mini` package alias to reduce bundled date-library size. Fixes: https://github.com/vycdev/vscode-todo-plus-two/issues/55 - Added default `@today` cleanup when archiving or marking todos done/cancelled, configurable with `todo.archive.remove.tags` and `todo.timekeeping.finished.remove.tags`. Fixes: https://github.com/vycdev/vscode-todo-plus-two/issues/30, https://github.com/vycdev/vscode-todo-plus-two/issues/13 - Added `todo.hoursPerDay` for configurable day length in short duration formatting. Fixes: https://github.com/vycdev/vscode-todo-plus-two/issues/16 +- Fixed short-duration weeks and years to use the configured `todo.hoursPerDay` day length consistently. - Fixed project and special-tag decorations so color/tag settings refresh without restart. Fixes: https://github.com/vycdev/vscode-todo-plus-two/issues/24, https://github.com/vycdev/vscode-todo-plus-two/issues/2 - Added `@created` and `@now` completions for inserting the current date/time anywhere in todo files. Fixes: https://github.com/vycdev/vscode-todo-plus-two/issues/38 - Fixed timestamp completions being offered inside inline code spans. diff --git a/src/utils/time.ts b/src/utils/time.ts index a0162ae..3e688d7 100644 --- a/src/utils/time.ts +++ b/src/utils/time.ts @@ -56,14 +56,15 @@ const Time = { let remaining = secondsAbs, parts = []; - const sections: [string, number][] = [ - ['y', 31536000], - ['w', 604800], - ['d', normalizedHoursPerDay * 3600], - ['h', 3600], - ['m', 60], - ['s', 1], - ]; + const daySeconds = normalizedHoursPerDay * 3600, + sections: [string, number][] = [ + ['y', 365 * daySeconds], + ['w', 7 * daySeconds], + ['d', daySeconds], + ['h', 3600], + ['m', 60], + ['s', 1], + ]; sections.forEach(([token, seconds]) => { const times = Math.floor(remaining / seconds); diff --git a/test/time.spec.ts b/test/time.spec.ts index 135626b..9777a4a 100644 --- a/test/time.spec.ts +++ b/test/time.spec.ts @@ -23,6 +23,18 @@ describe('Time utilities', () => { expect(Time.diff(to, from, 'short-compact', 8)).to.equal('3d1h'); }); + it('uses the configured day length for short weeks and years', () => { + const from = new Date('2020-01-01T00:00:00Z'), + configuredDay = 8 * 3600 * 1000; + + expect(Time.diff(new Date(from.getTime() + 8 * configuredDay), from, 'short', 8)).to.equal( + '1w 1d' + ); + expect( + Time.diff(new Date(from.getTime() + 366 * configuredDay), from, 'short-compact', 8) + ).to.equal('1y1d'); + }); + it('renders zero short durations as 0s', () => { const instant = new Date('2020-01-01T00:00:00Z');