Beispiel #1
0
    def test_strftime_old_date(self):
        fmt = "%Y-%m-%dT%H:%M:%S.%fZ"
        dt = Datetime(1800, 1, 1)

        s1 = Datetime.strftime(dt, fmt)
        s2 = dt.strftime(fmt)
        self.assertEqual(s1, s2)
        self.assertEqual("1800-01-01T00:00:00.000000Z", s1)
Beispiel #2
0
    def test_timestamp(self):
        d = Datetime()
        ts = d.timestamp()
        self.assertTrue(isinstance(ts, float))

        d2 = Datetime(ts)
        self.assertEqual(d, d2)

        d3 = Datetime(int(ts))
        self.assertEqual(d.strftime(Datetime.FORMAT_PRECISION_SECONDS),
                         d3.strftime(Datetime.FORMAT_PRECISION_SECONDS))
Beispiel #3
0
    def test_create(self):
        d1 = Datetime.utcnow()
        self.assertTrue(isinstance(d1, Datetime))

        d2 = Datetime()

        self.assertEqual(d1.strftime(Datetime.FORMAT_PRECISION_SECONDS),
                         d2.strftime(Datetime.FORMAT_PRECISION_SECONDS))

        d3 = Datetime(2018, 10, 5)
        d4 = Datetime(String(d3))
        self.assertEqual(d3.strftime(Datetime.FORMAT_PRECISION_DAY),
                         d4.strftime(Datetime.FORMAT_PRECISION_DAY))
Beispiel #4
0
    def test_convert(self):
        s = "2020-03-25T19:34:05.00005Z"
        dt = Datetime(s)
        self.assertEqual(50, dt.microsecond)
        self.assertEqual("2020-03-25T19:34:05.000050Z",
                         dt.strftime("%Y-%m-%dT%H:%M:%S.%fZ"))

        s = "2020-03-25T19:34:05.05Z"
        dt = Datetime(s)
        self.assertEqual(50000, dt.microsecond)
        self.assertEqual("2020-03-25T19:34:05.050000Z",
                         dt.strftime("%Y-%m-%dT%H:%M:%S.%fZ"))

        s = "2020-03-25T19:34:05.0506Z"
        dt = Datetime(s)
        self.assertEqual(50600, dt.microsecond)
        self.assertEqual("2020-03-25T19:34:05.050600Z",
                         dt.strftime("%Y-%m-%dT%H:%M:%S.%fZ"))

        s = "2020-03-25T19:34:05.050060Z"
        dt = Datetime(s)
        self.assertEqual(50060, dt.microsecond)
        self.assertEqual("2020-03-25T19:34:05.050060Z",
                         dt.strftime("%Y-%m-%dT%H:%M:%S.%fZ"))

        s = "2020-03-25T19:34:05.000057Z"
        dt = Datetime(s)
        self.assertEqual(57, dt.microsecond)
        self.assertEqual("2020-03-25T19:34:05.000057Z",
                         dt.strftime("%Y-%m-%dT%H:%M:%S.%fZ"))

        s = "2020-03-25T19:34:05.057Z"
        dt = Datetime(s)
        self.assertEqual(57000, dt.microsecond)
        self.assertEqual("2020-03-25T19:34:05.057000Z",
                         dt.strftime("%Y-%m-%dT%H:%M:%S.%fZ"))

        s = "2020-03-25T19:34:05.057035Z"
        dt = Datetime(s)
        self.assertEqual(57035, dt.microsecond)
        self.assertEqual("2020-03-25T19:34:05.057035Z",
                         dt.strftime("%Y-%m-%dT%H:%M:%S.%fZ"))

        s = "2020-03-19 00:00:00.000000000"
        dt = Datetime(s)
        self.assertEqual("2020-03-19T00:00:00.000000Z",
                         dt.strftime("%Y-%m-%dT%H:%M:%S.%fZ"))
Beispiel #5
0
 def test_strftime_str(self):
     dt = Datetime()
     s = dt.strftime("%m/%d/%Y")
     self.assertTrue(isinstance(s, Str))