feat: add localtime() function, app method
This commit is contained in:
parent
e76a6e5f6d
commit
dac91406c7
4 changed files with 122 additions and 0 deletions
|
|
@ -165,6 +165,51 @@ class TestLoadObject(TestCase):
|
|||
self.assertIs(result, TestCase)
|
||||
|
||||
|
||||
class TestLocaltime(TestCase):
|
||||
|
||||
def test_current_time(self):
|
||||
|
||||
# has tzinfo by default
|
||||
dt = mod.localtime()
|
||||
self.assertIsInstance(dt, datetime.datetime)
|
||||
self.assertIsNotNone(dt.tzinfo)
|
||||
now = datetime.datetime.now()
|
||||
self.assertAlmostEqual(int(dt.timestamp()), int(now.timestamp()))
|
||||
|
||||
# no tzinfo
|
||||
dt = mod.localtime(tzinfo=False)
|
||||
self.assertIsInstance(dt, datetime.datetime)
|
||||
self.assertIsNone(dt.tzinfo)
|
||||
now = datetime.datetime.now()
|
||||
self.assertAlmostEqual(int(dt.timestamp()), int(now.timestamp()))
|
||||
|
||||
def test_convert_with_tzinfo(self):
|
||||
sample = datetime.datetime(2024, 9, 15, 13, 30, tzinfo=datetime.timezone.utc)
|
||||
|
||||
# has tzinfo by default
|
||||
dt = mod.localtime(sample)
|
||||
self.assertIsInstance(dt, datetime.datetime)
|
||||
self.assertIsNotNone(dt.tzinfo)
|
||||
|
||||
# no tzinfo
|
||||
dt = mod.localtime(sample, tzinfo=False)
|
||||
self.assertIsInstance(dt, datetime.datetime)
|
||||
self.assertIsNone(dt.tzinfo)
|
||||
|
||||
def test_convert_without_tzinfo(self):
|
||||
sample = datetime.datetime(2024, 9, 15, 13, 30)
|
||||
|
||||
# has tzinfo by default
|
||||
dt = mod.localtime(sample)
|
||||
self.assertIsInstance(dt, datetime.datetime)
|
||||
self.assertIsNotNone(dt.tzinfo)
|
||||
|
||||
# no tzinfo
|
||||
dt = mod.localtime(sample, tzinfo=False)
|
||||
self.assertIsInstance(dt, datetime.datetime)
|
||||
self.assertIsNone(dt.tzinfo)
|
||||
|
||||
|
||||
class TestMakeUTC(TestCase):
|
||||
|
||||
def test_current_time(self):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue