How to use the datetimerange.__init__.DateTimeRange function in DateTimeRange

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 / datetimerange / __init__.py View on Github external
def __sub__(self, other):
        return DateTimeRange(self.start_datetime - other, self.end_datetime - other)
github thombashi / DateTimeRange / datetimerange / __init__.py View on Github external
def __add__(self, other):
        return DateTimeRange(self.start_datetime + other, self.end_datetime + other)
github thombashi / DateTimeRange / datetimerange / __init__.py View on Github external
.. parsed-literal::

                2015-03-22T10:05:00+0900 - 2015-03-22T10:10:00+0900
        """

        self.validate_time_inversion()
        x.validate_time_inversion()

        if any([x.start_datetime in self, self.start_datetime in x]):
            start_datetime = max(self.start_datetime, x.start_datetime)
            end_datetime = min(self.end_datetime, x.end_datetime)
        else:
            start_datetime = None
            end_datetime = None

        return DateTimeRange(
            start_datetime=start_datetime,
            end_datetime=end_datetime,
            start_time_format=self.start_time_format,
            end_time_format=self.end_time_format,
        )
github thombashi / DateTimeRange / datetimerange / __init__.py View on Github external
def __ne__(self, other):
        if not isinstance(other, DateTimeRange):
            return True

        return any(
            [self.start_datetime != other.start_datetime, self.end_datetime != other.end_datetime]
        )
github thombashi / DateTimeRange / datetimerange / __init__.py View on Github external
.. code:: python

                from datetimerange import DateTimeRange
                dtr0 = DateTimeRange("2015-03-22T10:00:00+0900", "2015-03-22T10:10:00+0900")
                dtr1 = DateTimeRange("2015-03-22T10:05:00+0900", "2015-03-22T10:15:00+0900")
                dtr0.encompass(dtr1)
        :Output:
            .. parsed-literal::

                2015-03-22T10:00:00+0900 - 2015-03-22T10:15:00+0900
        """

        self.validate_time_inversion()
        x.validate_time_inversion()

        return DateTimeRange(
            start_datetime=min(self.start_datetime, x.start_datetime),
            end_datetime=max(self.end_datetime, x.end_datetime),
            start_time_format=self.start_time_format,
            end_time_format=self.end_time_format,
        )

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