예제 #1
0
    def test_as_unit(self):
        ts = Timestamp("1970-01-01")

        assert ts._as_unit("ns") is ts

        res = ts._as_unit("us")
        assert res.value == ts.value // 1000
        assert res._reso == NpyDatetimeUnit.NPY_FR_us.value

        rt = res._as_unit("ns")
        assert rt.value == ts.value
        assert rt._reso == ts._reso

        res = ts._as_unit("ms")
        assert res.value == ts.value // 1_000_000
        assert res._reso == NpyDatetimeUnit.NPY_FR_ms.value

        rt = res._as_unit("ns")
        assert rt.value == ts.value
        assert rt._reso == ts._reso

        res = ts._as_unit("s")
        assert res.value == ts.value // 1_000_000_000
        assert res._reso == NpyDatetimeUnit.NPY_FR_s.value

        rt = res._as_unit("ns")
        assert rt.value == ts.value
        assert rt._reso == ts._reso
예제 #2
0
    def test_as_unit_non_nano(self):
        # case where we are going neither to nor from nano
        ts = Timestamp("1970-01-02")._as_unit("ms")
        assert ts.year == 1970
        assert ts.month == 1
        assert ts.day == 2
        assert ts.hour == ts.minute == ts.second == ts.microsecond == ts.nanosecond == 0

        res = ts._as_unit("s")
        assert res.value == 24 * 3600
        assert res.year == 1970
        assert res.month == 1
        assert res.day == 2
        assert (res.hour == res.minute == res.second == res.microsecond ==
                res.nanosecond == 0)