Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
DateTimeRange("2015-03-22T10:00:00+0900", "2015-03-22T10:10:00+0900"),
DateTimeRange("2015-03-22T10:02:00+0900", "2015-03-22T10:10:00+0900"),
False,
],
[
DateTimeRange("2015-03-22T10:00:00+0900", "2015-03-22T10:10:00+0900"),
DateTimeRange("2015-03-22T11:00:00+0900", "2015-03-22T12:10:00+0900"),
False,
],
[DateTimeRange(TEST_START_DATETIME, TEST_END_DATETIME), None, False],
[None, DateTimeRange(TEST_START_DATETIME, TEST_END_DATETIME), False],
],
)
def test_normal(self, lhs, rhs, expected):
assert (lhs == rhs) == expected
DateTimeRange("2015-03-22T11:00:00+0900", "2015-03-22T12:10:00+0900"),
False,
],
[DateTimeRange(TEST_START_DATETIME, TEST_END_DATETIME), None, False],
[None, DateTimeRange(TEST_START_DATETIME, TEST_END_DATETIME), False],
],
)
def test_normal(self, lhs, rhs, expected):
assert (lhs == rhs) == expected
def test_daylight_saving_time(self, start, end, expected):
dtr = DateTimeRange(start, end)
assert dtr.timedelta == expected
[DateTimeRange(TEST_START_DATETIME, None), False],
[DateTimeRange(None, TEST_START_DATETIME), False],
[DateTimeRange(None, None), False],
],
)
def test_normal(self, value, expected):
assert value.is_set() == expected
def datetimerange_inversion():
value = DateTimeRange(TEST_END_DATETIME, TEST_START_DATETIME)
value.start_time_format = ISO_TIME_FORMAT
value.end_time_format = ISO_TIME_FORMAT
return value
DateTimeRange("2015-01-22T10:00:00 JST", "2015-03-22T10:10:00 JST"),
True,
],
],
)
def test_normal(self, lhs, rhs, expected):
assert lhs.is_intersection(rhs) == expected
def test_exception(self, start, end, expected):
dtr = DateTimeRange()
with pytest.raises(expected):
dtr.set_time_range(start, end)
DateTimeRange("2015-03-22T10:10:00+0900", "2015-03-22T10:20:00+0900"),
],
[
DateTimeRange("2015-03-22T10:00:00", "2015-03-22T10:10:00"),
timedelta(seconds=-10 * 60),
DateTimeRange("2015-03-22T09:50:00", "2015-03-22T10:00:00"),
],
],
)
def test_normal(self, value, add_value, expected):
new_datetimerange = value + add_value
assert new_datetimerange == expected
DateTimeRange(datetime(2015, 3, 22, 0, 0, 0), datetime(2015, 3, 23, 0, 0, 0)),
relativedelta(months=+6),
[datetime(2015, 3, 22, 0, 0, 0)],
],
[
DateTimeRange("2015-01-01T00:00:00+0900", "2016-01-01T00:00:00+0900"),
relativedelta(months=+4),
[
parse("2015-01-01T00:00:00+0900"),
parse("2015-05-01T00:00:00+0900"),
parse("2015-09-01T00:00:00+0900"),
parse("2016-01-01T00:00:00+0900"),
],
],
[
DateTimeRange(datetime(2015, 3, 23, 0, 0, 0), datetime(2015, 3, 22, 0, 0, 0)),
relativedelta(hours=-6),
def test_normal(
self, start, start_format, end, end_format, separator, is_output_elapse, expected
):
dtr = DateTimeRange(start, end, start_format, end_format)
dtr.separator = separator
dtr.is_output_elapse = is_output_elapse
assert str(dtr) == expected