mirror of
https://github.com/borgbackup/borg.git
synced 2024-12-26 17:57:59 +00:00
Forward the format_spec
to datetime
class
If specified, the argument `format_spec` is forwarded from the method `OutputTimestamp.__format__` to the method `format_time` method. Thus, we are able to specify the format, in a way supported by the class `datetime`. The default behaviour of `format_time` is not affected. The other parts of code that does not provide a `format_spec` are not affected by the change.
This commit is contained in:
parent
3e22a0f653
commit
219e9d082a
1 changed files with 3 additions and 3 deletions
|
@ -747,11 +747,11 @@ def safe_timestamp(item_timestamp_ns):
|
||||||
return datetime.fromtimestamp(t_ns / 1e9)
|
return datetime.fromtimestamp(t_ns / 1e9)
|
||||||
|
|
||||||
|
|
||||||
def format_time(ts: datetime):
|
def format_time(ts: datetime, format_spec=''):
|
||||||
"""
|
"""
|
||||||
Convert *ts* to a human-friendly format with textual weekday.
|
Convert *ts* to a human-friendly format with textual weekday.
|
||||||
"""
|
"""
|
||||||
return ts.strftime('%a, %Y-%m-%d %H:%M:%S')
|
return ts.strftime('%a, %Y-%m-%d %H:%M:%S' if format_spec == '' else format_spec)
|
||||||
|
|
||||||
|
|
||||||
def isoformat_time(ts: datetime):
|
def isoformat_time(ts: datetime):
|
||||||
|
@ -786,7 +786,7 @@ def __init__(self, ts: datetime):
|
||||||
self.ts = ts
|
self.ts = ts
|
||||||
|
|
||||||
def __format__(self, format_spec):
|
def __format__(self, format_spec):
|
||||||
return format_time(self.ts)
|
return format_time(self.ts, format_spec=format_spec)
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return '{}'.format(self)
|
return '{}'.format(self)
|
||||||
|
|
Loading…
Reference in a new issue