From 4904106a72ba97a4aecbd0d58d75e9234436ea3e Mon Sep 17 00:00:00 2001 From: Adrian Sampson Date: Sat, 11 May 2013 13:10:31 -0700 Subject: [PATCH] config option for time format string --- beets/config_default.yaml | 1 + beets/library.py | 10 ++++------ test/test_db.py | 3 ++- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/beets/config_default.yaml b/beets/config_default.yaml index 210d7f1db..d7b14175f 100644 --- a/beets/config_default.yaml +++ b/beets/config_default.yaml @@ -49,6 +49,7 @@ ui: list_format_item: $artist - $album - $title list_format_album: $albumartist - $album +time_format: '%Y-%m-%d %H:%M:%S' paths: default: $albumartist/$album%aunique{}/$track $title diff --git a/beets/library.py b/beets/library.py index 2b2a2cd20..49e22858b 100644 --- a/beets/library.py +++ b/beets/library.py @@ -37,10 +37,6 @@ import beets MAX_FILENAME_LENGTH = 200 -# This is the default format when printing the import time -# of an object. This needs to be a format accepted by time.strftime() -ITIME_FORMAT = '%Y-%m-%d %H:%M:%S' - # Fields in the "items" database table; all the metadata available for # items in the library. These are used directly in SQL; they are # vulnerable to injection if accessible to the user. @@ -211,7 +207,8 @@ def format_for_path(value, key=None, pathmod=None): value = u'%ikHz' % ((value or 0) // 1000) elif key in ('itime', 'mtime'): # Times are formatted to be human-readable. - value = time.strftime(ITIME_FORMAT, time.localtime(value)) + value = time.strftime(beets.config['time_format'].get(unicode), + time.localtime(value)) value = unicode(value) elif value is None: value = u'' @@ -1840,7 +1837,8 @@ class DefaultTemplateFunctions(object): def tmpl_format(s, format): """Format the import time to any format according to time.strfime() """ - return time.strftime(format, time.strptime(s, ITIME_FORMAT)) + cur_fmt = beets.config['time_format'].get(unicode) + return time.strftime(format, time.strptime(s, cur_fmt)) def tmpl_aunique(self, keys=None, disam=None): """Generate a string that is guaranteed to be unique among all diff --git a/test/test_db.py b/test/test_db.py index 7f6902794..76d99087c 100644 --- a/test/test_db.py +++ b/test/test_db.py @@ -980,8 +980,9 @@ class MtimeTest(_common.TestCase): self.i.read() self.assertGreaterEqual(self.i.mtime, self._mtime()) -class ImportTimeTest(unittest.TestCase): +class ImportTimeTest(_common.TestCase): def setUp(self): + super(ImportTimeTest, self).setUp() self.lib = beets.library.Library(':memory:') def test_itime_for_album(self):