Allow unicode characters in time segment in Python-2
This commit is contained in:
parent
aa33599e3f
commit
c6a6041b0d
|
@ -16,8 +16,13 @@ def date(pl, format='%Y-%m-%d', istime=False):
|
|||
|
||||
Highlight groups used: ``time`` or ``date``.
|
||||
'''
|
||||
try:
|
||||
contents = datetime.now().strftime(format)
|
||||
except UnicodeEncodeError:
|
||||
contents = datetime.now().strftime(format.encode('utf-8')).decode('utf-8')
|
||||
|
||||
return [{
|
||||
'contents': datetime.now().strftime(format),
|
||||
'contents': contents,
|
||||
'highlight_groups': (['time'] if istime else []) + ['date'],
|
||||
'divider_highlight_group': 'time:divider' if istime else None,
|
||||
}]
|
||||
|
|
|
@ -709,6 +709,7 @@ class TestTime(TestCommon):
|
|||
with replace_attr(self.module, 'datetime', Args(now=lambda: Args(strftime=lambda fmt: fmt))):
|
||||
self.assertEqual(self.module.date(pl=pl), [{'contents': '%Y-%m-%d', 'highlight_groups': ['date'], 'divider_highlight_group': None}])
|
||||
self.assertEqual(self.module.date(pl=pl, format='%H:%M', istime=True), [{'contents': '%H:%M', 'highlight_groups': ['time', 'date'], 'divider_highlight_group': 'time:divider'}])
|
||||
self.assertEqual(self.module.date(pl=pl, format='\u231a', istime=True), [{'contents': '\u231a', 'highlight_groups': ['time', 'date'], 'divider_highlight_group': 'time:divider'}])
|
||||
|
||||
def test_fuzzy_time(self):
|
||||
time = Args(hour=0, minute=45)
|
||||
|
|
Loading…
Reference in New Issue