Commit 8110854e by Owo Sugiana

Bug fixed timestamp with time zone

1 parent 0fe01e9e
......@@ -18,8 +18,8 @@ def get_timezone():
def create_datetime(
year, month, day, hour=0, minute=7, second=0, microsecond=0):
tz = get_timezone()
return datetime(
year, month, day, hour, minute, second, microsecond, tzinfo=tz)
without_tz = datetime(year, month, day, hour, minute, second, microsecond)
return tz.localize(without_tz)
def create_date(year, month, day):
......
import unittest
import pytz
from datetime import (
date,
datetime,
)
from opensipkd.waktu import create_datetime
class ZonaWaktu(unittest.TestCase):
def setUp(self):
self.from_str = '2020-10-15 13:59:32,595'
def test_to_str(self):
without_tz = datetime.strptime(self.from_str, '%Y-%m-%d %H:%M:%S,%f')
with_tz = create_datetime(
without_tz.year, without_tz.month, without_tz.day,
without_tz.hour, without_tz.minute, without_tz.second,
without_tz.microsecond)
to_str = with_tz.strftime('%Y-%m-%d %H:%M:%S,%f')
to_str = to_str.rstrip('0')
self.assertEqual(self.from_str, to_str)
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!