fix: add app.today() convenience method
This commit is contained in:
parent
be6ac16ea7
commit
b09b991d15
2 changed files with 17 additions and 1 deletions
|
|
@ -630,7 +630,8 @@ class AppHandler: # pylint: disable=too-many-public-methods
|
||||||
|
|
||||||
For usage examples see :ref:`convert-to-localtime`.
|
For usage examples see :ref:`convert-to-localtime`.
|
||||||
|
|
||||||
See also :meth:`make_utc()` which is sort of the inverse.
|
See also :meth:`make_utc()` which is sort of the inverse; and
|
||||||
|
:meth:`today()`.
|
||||||
"""
|
"""
|
||||||
kw["local_zone"] = local_zone or self.get_timezone()
|
kw["local_zone"] = local_zone or self.get_timezone()
|
||||||
return localtime(dt=dt, **kw)
|
return localtime(dt=dt, **kw)
|
||||||
|
|
@ -647,6 +648,17 @@ class AppHandler: # pylint: disable=too-many-public-methods
|
||||||
"""
|
"""
|
||||||
return make_utc(dt=dt, tzinfo=tzinfo)
|
return make_utc(dt=dt, tzinfo=tzinfo)
|
||||||
|
|
||||||
|
def today(self):
|
||||||
|
"""
|
||||||
|
Convenience method to return the current date, according
|
||||||
|
to local time zone.
|
||||||
|
|
||||||
|
See also :meth:`localtime()`.
|
||||||
|
|
||||||
|
:returns: :class:`python:datetime.date` instance
|
||||||
|
"""
|
||||||
|
return self.localtime().date()
|
||||||
|
|
||||||
# TODO: deprecate / remove this eventually
|
# TODO: deprecate / remove this eventually
|
||||||
def make_true_uuid(self):
|
def make_true_uuid(self):
|
||||||
"""
|
"""
|
||||||
|
|
|
||||||
|
|
@ -510,6 +510,10 @@ app_title = WuttaTest
|
||||||
self.assertIsInstance(dt, datetime.datetime)
|
self.assertIsInstance(dt, datetime.datetime)
|
||||||
self.assertIsNone(dt.tzinfo)
|
self.assertIsNone(dt.tzinfo)
|
||||||
|
|
||||||
|
def test_today(self):
|
||||||
|
today = self.app.today()
|
||||||
|
self.assertIsInstance(today, datetime.date)
|
||||||
|
|
||||||
def test_make_str_uuid(self):
|
def test_make_str_uuid(self):
|
||||||
uuid = self.app.make_str_uuid()
|
uuid = self.app.make_str_uuid()
|
||||||
self.assertEqual(len(uuid), 32)
|
self.assertEqual(len(uuid), 32)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue