Skip to content

Commit

Permalink
Add support for weeks in timespans, change Y to y.
Browse files Browse the repository at this point in the history
This is initial response to comments made on pull request.  Will look at
--keep-within in a bit.
  • Loading branch information
Ken Kundert authored and Ken Kundert committed Jan 6, 2025
1 parent ddf51cb commit b3dc5a5
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
8 changes: 4 additions & 4 deletions docs/usage/general/date-time.rst.inc
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Internally, we store and process date and time as UTC.

.. rubric:: TIMESPAN

Some options accept a TIMESPAN parameter, which can be given as a
number of years (e.g. ``2Y``), months (e.g. ``12m``), days (e.g. ``7d``),
hours (e.g. ``8H``), minutes (e.g. ``30M``), or seconds (e.g. ``84600s``).

Some options accept a TIMESPAN parameter, which can be given as a number of
years (e.g. ``2y``), months (e.g. ``12m``), weeks (e.g. ``2w``),
days (e.g. ``7d``), hours (e.g. ``8H``), minutes (e.g. ``30M``),
or seconds (e.g. ``150S``).
4 changes: 2 additions & 2 deletions src/borg/helpers/parseformat.py
Original file line number Diff line number Diff line change
Expand Up @@ -579,10 +579,10 @@ def validator(text):


def relative_time_marker_validator(text: str):
time_marker_regex = r"^\d+[YmdHMS]$"
time_marker_regex = r"^\d+[ymwdHMS]$"
match = re.compile(time_marker_regex).search(text)
if not match:
raise argparse.ArgumentTypeError(f"Invalid relative time marker used: {text}, choose from Y, m, d, H, M, S")
raise argparse.ArgumentTypeError(f"Invalid relative time marker used: {text}, choose from y, m, w, d, H, M, S")
else:
return text

Expand Down
4 changes: 3 additions & 1 deletion src/borg/helpers/time.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,10 @@ def calculate_relative_offset(format_string, from_ts, earlier=False):
return from_ts + timedelta(days=offset)
elif unit == "m":
return offset_n_months(from_ts, offset)
elif unit == "Y":
elif unit == "y":
return from_ts.replace(year=from_ts.year + offset)
elif unit == "w":
return from_ts + timedelta(days=offset * 7)
elif unit == "H":
return from_ts + timedelta(seconds=offset * 60 * 60)
elif unit == "M":
Expand Down

0 comments on commit b3dc5a5

Please sign in to comment.