config option for time format string

This commit is contained in:
Adrian Sampson 2013-05-11 13:10:31 -07:00
parent 24c90b565a
commit 4904106a72
3 changed files with 7 additions and 7 deletions

View file

@ -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

View file

@ -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

View file

@ -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):