Skip to content

borg2: ValueError due to leap year confusion in calculate_relative_offset() #9967

Description

@PhrozenByte

There's a minor bug in helpers.time.calculate_relative_offset() (currently used by borg2 repo-list --oldest/--newest/--older/--newer; possible future use by borg2 check --max-age (#9925) and borg2 prune --keep (#9929)) that raises an error when a year-based interval is applied relative to February 29 and the resulting year is not a leap year.

For example, with from_ts = datetime(2024, 2, 29) and format_string = "1y", the following code raises: ValueError: day 29 must be in range 1..28 for month 2 in year 2025

return from_ts.replace(year=from_ts.year + offset)

Suggested fix:

return offset_n_months(from_ts, offset * 12)

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions