Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
17 changes: 9 additions & 8 deletions src/utils/time.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
12 changes: 12 additions & 0 deletions test/time.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand Down
Loading