Exemple #1
0
 def __add__(self, other):
     if isinstance(other, Duration):
         return Duration(months=self[0] + int(other[0]), days=self[1] + int(other[1]),
                         seconds=self[2] + int(other[2]), subseconds=nano_add(self[3], other[3]))
     if isinstance(other, timedelta):
         return Duration(months=self[0], days=self[1] + int(other.days),
                         seconds=self[2] + int(other.seconds),
                         subseconds=nano_add(self[3], other.microseconds / 1000000))
     return NotImplemented
 def test_from_native(self):
     native = time(12, 34, 56, 789123)
     t = Time.from_native(native)
     self.assertEqual(t.hour, native.hour)
     self.assertEqual(t.minute, native.minute)
     self.assertEqual(
         t.second,
         nano_add(native.second, nano_div(native.microsecond, 1000000)))
 def test_to_native(self):
     t = Time(12, 34, 56.789123456)
     native = t.to_native()
     self.assertEqual(t.hour, native.hour)
     self.assertEqual(t.minute, native.minute)
     self.assertEqual(
         56.789123,
         nano_add(native.second, nano_div(native.microsecond, 1000000)))
def test_from_native_case_2():
    # python -m pytest tests/unit/time/test_time.py -s -v -k test_from_native_case_2
    native = time(12, 34, 56, 789123, FixedOffset(0))
    t = Time.from_native(native)
    assert t.hour == native.hour
    assert t.minute == native.minute
    assert t.second == nano_add(native.second, nano_div(native.microsecond, 1000000))
    assert t.tzinfo == FixedOffset(0)
Exemple #5
0
def test_to_native_case_2():
    # python -m pytest tests/unit/time/test_datetime.py -s -v -k test_to_native_case_2
    dt = DateTime.from_iso_format("2019-10-30T12:34:56.789123456+00:00")
    native = dt.to_native()
    assert native.hour == dt.hour
    assert native.minute == dt.minute
    assert nano_add(native.second, nano_div(native.microsecond, 1000000)) == 56.789123
    assert native.tzinfo == FixedOffset(0)
    assert native.isoformat() == "2019-10-30T12:34:56.789123+00:00"
Exemple #6
0
 def test_to_native(self):
     dt = DateTime(2018, 10, 1, 12, 34, 56.789123456)
     native = dt.to_native()
     self.assertEqual(dt.year, native.year)
     self.assertEqual(dt.month, native.month)
     self.assertEqual(dt.day, native.day)
     self.assertEqual(dt.hour, native.hour)
     self.assertEqual(dt.minute, native.minute)
     self.assertEqual(56.789123, nano_add(native.second, nano_div(native.microsecond, 1000000)))
Exemple #7
0
 def test_from_native(self):
     native = datetime(2018, 10, 1, 12, 34, 56, 789123)
     dt = DateTime.from_native(native)
     self.assertEqual(dt.year, native.year)
     self.assertEqual(dt.month, native.month)
     self.assertEqual(dt.day, native.day)
     self.assertEqual(dt.hour, native.hour)
     self.assertEqual(dt.minute, native.minute)
     self.assertEqual(dt.second, nano_add(native.second, nano_div(native.microsecond, 1000000)))
def test_to_native_case_2():
    # python -m pytest tests/unit/time/test_time.py -s -v -k test_to_native_case_2
    t = Time(12, 34, 56.789123456, tzinfo=timezone_utc)
    native = t.to_native()
    assert native.hour == t.hour
    assert native.minute == t.minute
    assert nano_add(native.second, nano_div(native.microsecond, 1000000)) == 56.789123
    assert native.tzinfo == FixedOffset(0)
    assert native.isoformat() == "12:34:56.789123+00:00"
def test_to_native_case_1():
    # python -m pytest tests/unit/time/test_time.py -s -v -k test_to_native_case_1
    t = Time(12, 34, 56.789123456)
    native = t.to_native()
    assert native.hour == t.hour
    assert native.minute == t.minute
    assert nano_add(native.second, nano_div(native.microsecond, 1000000)) == 56.789123
    assert native.tzinfo is None
    assert native.isoformat() == "12:34:56.789123"
Exemple #10
0
def test_from_native_case_2():
    # python -m pytest tests/unit/time/test_datetime.py -s -v -k test_from_native_case_2
    native = datetime(2018, 10, 1, 12, 34, 56, 789123, FixedOffset(0))
    dt = DateTime.from_native(native)
    assert dt.year == native.year
    assert dt.month == native.month
    assert dt.day == native.day
    assert dt.hour == native.hour
    assert dt.minute == native.minute
    assert dt.second == nano_add(native.second, nano_div(native.microsecond, 1000000))
    assert dt.tzinfo == FixedOffset(0)
Exemple #11
0
 def __mod__(self, other):
     if isinstance(other, int):
         seconds, subseconds = symmetric_divmod(nano_add(self[2], self[3]) % other, 1)
         return Duration(months=round_half_to_even(self[0] % other), days=round_half_to_even(self[1] % other),
                         seconds=seconds, subseconds=subseconds)
     return NotImplemented
Exemple #12
0
 def __floordiv__(self, other):
     if isinstance(other, int):
         return Duration(months=int(self[0] // other), days=int(self[1] // other),
                         seconds=int(nano_add(self[2], self[3]) // other), subseconds=0)
     return NotImplemented