feat(parse): add parse_duration_to_days for duration string conversion
Problem: The archive command accepted only a bare integer for days, inconsistent with the `+Nd`/`+Nw`/`+Nm` duration syntax used elsewhere. Solution: Add `parse_duration_to_days()` supporting `Nd`, `Nw`, `Nm`, and bare integers. Returns nil on invalid input for caller error handling.
This commit is contained in:
parent
c5d55e5e92
commit
8cfdafe464
2 changed files with 67 additions and 0 deletions
|
|
@ -416,6 +416,48 @@ describe('parse', function()
|
|||
end)
|
||||
end)
|
||||
|
||||
describe('parse_duration_to_days', function()
|
||||
it('parses days suffix', function()
|
||||
assert.are.equal(7, parse.parse_duration_to_days('7d'))
|
||||
end)
|
||||
|
||||
it('parses weeks suffix', function()
|
||||
assert.are.equal(21, parse.parse_duration_to_days('3w'))
|
||||
end)
|
||||
|
||||
it('parses months suffix (approximated as 30 days)', function()
|
||||
assert.are.equal(60, parse.parse_duration_to_days('2m'))
|
||||
end)
|
||||
|
||||
it('parses bare integer as days', function()
|
||||
assert.are.equal(30, parse.parse_duration_to_days('30'))
|
||||
end)
|
||||
|
||||
it('returns nil for nil input', function()
|
||||
assert.is_nil(parse.parse_duration_to_days(nil))
|
||||
end)
|
||||
|
||||
it('returns nil for empty string', function()
|
||||
assert.is_nil(parse.parse_duration_to_days(''))
|
||||
end)
|
||||
|
||||
it('returns nil for unrecognized input', function()
|
||||
assert.is_nil(parse.parse_duration_to_days('xyz'))
|
||||
end)
|
||||
|
||||
it('returns nil for negative numbers', function()
|
||||
assert.is_nil(parse.parse_duration_to_days('-7d'))
|
||||
end)
|
||||
|
||||
it('handles single digit', function()
|
||||
assert.are.equal(1, parse.parse_duration_to_days('1d'))
|
||||
end)
|
||||
|
||||
it('handles large numbers', function()
|
||||
assert.are.equal(365, parse.parse_duration_to_days('365d'))
|
||||
end)
|
||||
end)
|
||||
|
||||
describe('input_date_formats', function()
|
||||
before_each(function()
|
||||
config.reset()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue