How to use DateTimeRange - 10 common examples

To help you get started, we’ve selected a few DateTimeRange examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github thombashi / DateTimeRange / test / test_dtr.py View on Github external
                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
github thombashi / DateTimeRange / test / test_dtr.py View on Github external
                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
github thombashi / DateTimeRange / test / test_dtr.py View on Github external
def test_daylight_saving_time(self, start, end, expected):
        dtr = DateTimeRange(start, end)
        assert dtr.timedelta == expected
github thombashi / DateTimeRange / test / test_dtr.py View on Github external
            [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
github thombashi / DateTimeRange / test / test_dtr.py View on Github external
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
github thombashi / DateTimeRange / test / test_dtr.py View on Github external
                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
github thombashi / DateTimeRange / test / test_dtr.py View on Github external
def test_exception(self, start, end, expected):
        dtr = DateTimeRange()
        with pytest.raises(expected):
            dtr.set_time_range(start, end)
github thombashi / DateTimeRange / test / test_dtr.py View on Github external
                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
github thombashi / DateTimeRange / test / test_dtr.py View on Github external
                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),
github thombashi / DateTimeRange / test / test_dtr.py View on Github external
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

DateTimeRange

DateTimeRange is a Python library to handle a time range. e.g. check whether a time is within the time range, get the intersection of time ranges, truncate a time range, iterate through a time range, and so forth.

MIT
Latest version published 7 months ago

Package Health Score

62 / 100
Full package analysis

Similar packages