Repository: borgbackup/borg

Issue:
switch date/time format to iso style
currently: american style
wanted: iso style, like 2015-12-31 23:59:59

e.g. in "info" command, maybe also at other places.



Discussion:
I much prefer the ISO style, not least because the string sorts usefully

On 5 November 2015 at 03:19, TW notifications@github.com wrote:

> currently: american style
> wanted: iso style, like 2015-12-31 23:59:59
> 
> e.g. in "info" command, maybe also at other places.
> 
> —
> Reply to this email directly or view it on GitHub
> https://github.com/borgbackup/borg/issues/375.

This is what's currently in the code:

```
def format_time(t):
    """Format datetime suitable for fixed length list output
    """
    if abs((datetime.now() - t).days) < 365:
        return t.strftime('%b %d %H:%M')    # AAA
    else:
        return t.strftime('%b %d  %Y')   # BBB
```

Output of these + iso format as CCC looks like:

```
drwxrwxr-x tw     tw            0 Oct 12 00:08 AAA
drwxrwxr-x tw     tw            0 Oct 12  2013 BBB
drwxrwxr-x tw     tw            0 2015-10-12 00:08 CCC
```

So, it needs 5 colums more space.
But is way easier to grep for as it is always formatted in the same easy way.
Shall we even add 3 more columns for the seconds?

Yeah, add 3 columns for the seconds.

80 column terminals are soooo 1980's... ;-)

On 7 November 2015 at 02:02, TW notifications@github.com wrote:

> This is what's currently in the code:
> 
> def format_time(t):
>     """Format datetime suitable for fixed length list output
>     """
>     if abs((datetime.now() - t).days) < 365:
>         return t.strftime('%b %d %H:%M')    # AAA
>     else:
>         return t.strftime('%b %d  %Y')   # BBB
> 
> Output of these + iso format as CCC looks like:
> 
> drwxrwxr-x tw     tw            0 Oct 12 00:08 AAA
> drwxrwxr-x tw     tw            0 Oct 12  2013 BBB
> drwxrwxr-x tw     tw            0 2015-10-12 00:08 CCC
> 
> So, it needs 5 colums more space.
> But is way easier to grep for as it is always formatted in the same easy
> way.
> Shall we even add 3 more columns for the seconds?
> 
> —
> Reply to this email directly or view it on GitHub
> https://github.com/borgbackup/borg/issues/375#issuecomment-154431531.

that makes the formatter simple, '%F %T'

On 2015-11-06 15:10, level323 wrote:

> Yeah, add 3 columns for the seconds.
> 
> 80 column terminals are soooo 1980's... ;-)
> 
> On 7 November 2015 at 02:02, TW notifications@github.com wrote:
> 
> > This is what's currently in the code:
> > 
> > def format_time(t):
> > """Format datetime suitable for fixed length list output
> > """
> > if abs((datetime.now() - t).days) < 365:
> > return t.strftime('%b %d %H:%M') # AAA
> > else:
> > return t.strftime('%b %d %Y') # BBB
> > 
> > Output of these + iso format as CCC looks like:
> > 
> > drwxrwxr-x tw tw 0 Oct 12 00:08 AAA
> > drwxrwxr-x tw tw 0 Oct 12 2013 BBB
> > drwxrwxr-x tw tw 0 2015-10-12 00:08 CCC
> > 
> > So, it needs 5 colums more space.
> > But is way easier to grep for as it is always formatted in the same easy
> > way.
> > Shall we even add 3 more columns for the seconds?
> > 
> > —
> > Reply to this email directly or view it on GitHub
> > https://github.com/borgbackup/borg/issues/375#issuecomment-154431531.
> 
> —
> Reply to this email directly or view it on GitHub
> https://github.com/borgbackup/borg/issues/375#issuecomment-154433417.

I don't think the seconds are useful information here and it's not worth breaking good old 80 column compatibility for that.

It's not like "iso-format-with-seconds" or "without" breaks 80 chars wide display, it would just leave less space for filenames as the current format (and that is true for both with-secs and without-secs).

My original comment about 80 char wide display was my poor attempt at
humour - nothing more. Borg never did anything special to stay within 80
column wide output in the first place, AFAIK.

Sorry for any confusion.

On 8 November 2015 at 23:54, TW notifications@github.com wrote:

> It's not like "iso-format-with-seconds" or "without" breaks 80 chars wide
> display, it would just leave less space for filenames as the current format
> (and that is true for both with-secs and without-secs).
> 
> —
> Reply to this email directly or view it on GitHub
> https://github.com/borgbackup/borg/issues/375#issuecomment-154825056.

go with seconds, i would say.

nanoseconds even, if available.


Resolving patch:
diff --git a/borg/archiver.py b/borg/archiver.py
--- a/borg/archiver.py
+++ b/borg/archiver.py
@@ -431,7 +431,7 @@ def do_info(self, args):
         print('Fingerprint: %s' % hexlify(archive.id).decode('ascii'))
         print('Hostname:', archive.metadata[b'hostname'])
         print('Username:', archive.metadata[b'username'])
-        print('Time: %s' % to_localtime(archive.ts).strftime('%c'))
+        print('Time: %s' % format_time(to_localtime(archive.ts)))
         print('Command line:', remove_surrogates(' '.join(archive.metadata[b'cmdline'])))
         print('Number of files: %d' % stats.nfiles)
         print()
diff --git a/borg/helpers.py b/borg/helpers.py
--- a/borg/helpers.py
+++ b/borg/helpers.py
@@ -449,12 +449,9 @@ def dir_is_tagged(path, exclude_caches, exclude_if_present):
 
 
 def format_time(t):
-    """Format datetime suitable for fixed length list output
+    """use ISO-8601 date and time format
     """
-    if abs((datetime.now() - t).days) < 365:
-        return t.strftime('%b %d %H:%M')
-    else:
-        return t.strftime('%b %d  %Y')
+    return t.strftime('%Y-%m-%d %H:%M:%S')
 
 
 def format_timedelta(td):
@@ -510,7 +507,7 @@ def sizeof_fmt_decimal(num, suffix='B', sep='', precision=2):
 
 
 def format_archive(archive):
-    return '%-36s %s' % (archive.name, to_localtime(archive.ts).strftime('%c'))
+    return '%-36s %s' % (archive.name, format_time(to_localtime(archive.ts)))
 
 
 def memoize(function):
diff --git a/docs/conf.py b/docs/conf.py
--- a/docs/conf.py
+++ b/docs/conf.py
@@ -63,7 +63,7 @@
 # non-false value, then it is used:
 #today = ''
 # Else, today_fmt is used as the format for a strftime call.
-#today_fmt = '%B %d, %Y'
+today_fmt = '%Y-%m-%d'
 
 # List of patterns, relative to source directory, that match files and
 # directories to ignore when looking for source files.
@@ -131,7 +131,7 @@
 
 # If not '', a 'Last updated on:' timestamp is inserted at every page bottom,
 # using the given strftime format.
-#html_last_updated_fmt = '%b %d, %Y'
+html_last_updated_fmt = '%Y-%m-%d'
 
 # If true, SmartyPants will be used to convert quotes and dashes to
 # typographically correct entities.


Test patch: