parent
71840a14d3
commit
18a09e341c
3 changed files with 25 additions and 6 deletions
|
|
@ -276,7 +276,9 @@ class CmdMail(default_cmds.MuxAccountCommand):
|
||||||
if message:
|
if message:
|
||||||
messageForm.append(_HEAD_CHAR * _WIDTH)
|
messageForm.append(_HEAD_CHAR * _WIDTH)
|
||||||
messageForm.append("|wFrom:|n %s" % (message.senders[0].get_display_name(self.caller)))
|
messageForm.append("|wFrom:|n %s" % (message.senders[0].get_display_name(self.caller)))
|
||||||
messageForm.append("|wSent:|n %s" % message.db_date_created.strftime("%b %-d, %Y - %H:%M:%S"))
|
# note that we cannot use %-d format here since Windows does not support it
|
||||||
|
day = message.db_date_created.day
|
||||||
|
messageForm.append("|wSent:|n %s" % message.db_date_created.strftime(f"%b {day}, %Y - %H:%M:%S"))
|
||||||
messageForm.append("|wSubject:|n %s" % message.header)
|
messageForm.append("|wSubject:|n %s" % message.header)
|
||||||
messageForm.append(_SUB_HEAD_CHAR * _WIDTH)
|
messageForm.append(_SUB_HEAD_CHAR * _WIDTH)
|
||||||
messageForm.append(message.message)
|
messageForm.append(message.message)
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,9 @@ TODO: Not nearly all utilities are covered yet.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
import mock
|
||||||
from django.test import TestCase
|
from django.test import TestCase
|
||||||
|
from datetime import datetime
|
||||||
|
|
||||||
from evennia.utils.ansi import ANSIString
|
from evennia.utils.ansi import ANSIString
|
||||||
from evennia.utils import utils
|
from evennia.utils import utils
|
||||||
|
|
@ -186,3 +188,18 @@ class TestTimeformat(TestCase):
|
||||||
"""Test that unknown formats raise exceptions."""
|
"""Test that unknown formats raise exceptions."""
|
||||||
self.assertRaises(ValueError, utils.time_format, 0, 5)
|
self.assertRaises(ValueError, utils.time_format, 0, 5)
|
||||||
self.assertRaises(ValueError, utils.time_format, 0, "u")
|
self.assertRaises(ValueError, utils.time_format, 0, "u")
|
||||||
|
|
||||||
|
|
||||||
|
@mock.patch("evennia.utils.utils.timezone.now",
|
||||||
|
new=mock.MagicMock(return_value=datetime(2019, 8, 28, 21, 56)))
|
||||||
|
class TestDateTimeFormat(TestCase):
|
||||||
|
|
||||||
|
def test_datetimes(self):
|
||||||
|
dtobj = datetime(2017, 7, 26, 22, 54)
|
||||||
|
self.assertEqual(utils.datetime_format(dtobj), "Jul 26, 2017")
|
||||||
|
dtobj = datetime(2019, 7, 26, 22, 54)
|
||||||
|
self.assertEqual(utils.datetime_format(dtobj), "Jul 26")
|
||||||
|
dtobj = datetime(2019, 8, 28, 19, 54)
|
||||||
|
self.assertEqual(utils.datetime_format(dtobj), "19:54")
|
||||||
|
dtobj = datetime(2019, 8, 28, 21, 32)
|
||||||
|
self.assertEqual(utils.datetime_format(dtobj), "21:32:00")
|
||||||
|
|
|
||||||
|
|
@ -577,10 +577,10 @@ def datetime_format(dtobj):
|
||||||
|
|
||||||
if dtobj.year < now.year:
|
if dtobj.year < now.year:
|
||||||
# another year (Apr 5, 2019)
|
# another year (Apr 5, 2019)
|
||||||
timestring = dtobj.strftime("%b %-d, %Y")
|
timestring = dtobj.strftime(f"%b {dtobj.day}, %Y")
|
||||||
elif dtobj.date() < now.date():
|
elif dtobj.date() < now.date():
|
||||||
# another date, same year (Apr 5)
|
# another date, same year (Apr 5)
|
||||||
timestring = dtobj.strftime("%b %-d")
|
timestring = dtobj.strftime(f"%b {dtobj.day}")
|
||||||
elif dtobj.hour < now.hour - 1:
|
elif dtobj.hour < now.hour - 1:
|
||||||
# same day, more than 1 hour ago (10:45)
|
# same day, more than 1 hour ago (10:45)
|
||||||
timestring = dtobj.strftime("%H:%M")
|
timestring = dtobj.strftime("%H:%M")
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue