From 1d6e4ba9eee8e78ce621129829d9185ca8deb80f Mon Sep 17 00:00:00 2001 From: vycdev2 Date: Mon, 28 Sep 2026 04:04:36 +0000 Subject: [PATCH] fix: accept explicit positive duration signs --- CHANGELOG.md | 1 + src/utils/time.ts | 6 +++--- test/time.spec.ts | 8 ++++++++ 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e4ea9f9..cbb21ca 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ #### Review fixes +- Accepted an explicit leading `+` in time estimates and other duration expressions, alongside existing negative durations. - Preserved balanced closing parentheses, brackets, and braces in relative file-link filenames while excluding surrounding punctuation. - Preserved unsaved archive buffers, serialized simultaneous transfers, and replaced closed archive files only after a complete write. Failed writes, stale source documents, and rejected editor edits keep source tasks intact. - Preserved archive task order, sibling project structure, attached comment indentation, and standalone notes when removing empty projects. diff --git a/src/utils/time.ts b/src/utils/time.ts index 3e688d7..dc4d17f 100644 --- a/src/utils/time.ts +++ b/src/utils/time.ts @@ -247,13 +247,13 @@ const Time = { normalizedDaysPerWeek = Math.max(1, Number(manDaysPerWeek) || 5); if ( - /^\s*-\s*\d/.test(to) && + /^\s*[+-]\s*\d/.test(to) && /\d+(?:\.\d+)?\s*(?:m[dw]|ms|[smhdwy]|seconds?|minutes?|hours?|days?|weeks?|years?)(?=\d|\W|$)/i.test( to ) ) { - durationSign = -1; - to = to.replace(/^\s*-\s*/, ''); + durationSign = /^\s*-/.test(to) ? -1 : 1; + to = to.replace(/^\s*[+-]\s*/, ''); } to = to.replace(/(\d+(?:\.\d+)?)\s*mw(?=\d|\W|$)/gi, (match, weeks) => { diff --git a/test/time.spec.ts b/test/time.spec.ts index 9777a4a..36dda38 100644 --- a/test/time.spec.ts +++ b/test/time.spec.ts @@ -128,6 +128,14 @@ describe('Time utilities', () => { expect(Time.diff(formatted, from, 'man-weeks', 24, 6, 3)).to.equal(formatted); }); + it('accepts an explicit positive sign on duration expressions', () => { + const from = new Date('2020-01-01T00:00:00Z'); + + expect(Time.durationSeconds('+1h 30m', from)).to.equal(90 * 60); + expect(Time.diffSeconds(' + 2md 1h', from, 8, 5)).to.equal(17 * 3600); + expect(Time.diff('+1h 30m', from, 'short')).to.equal('1h 30m'); + }); + it('applies a leading sign to complete man-time durations', () => { const from = new Date('2020-01-01T00:00:00Z'), negativeManDay = Time.diff(