From 96e6ed8831fd53501db0ab5d17ac443434b8340b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Eustace?= Date: Sun, 20 Nov 2022 20:23:40 +0100 Subject: [PATCH] Rename the Period class to Interval --- pendulum/__init__.py | 10 ++++---- pendulum/date.py | 10 ++++---- pendulum/datetime.py | 16 ++++++------ pendulum/{period.py => interval.py} | 25 +++++++++---------- pendulum/parser.py | 10 ++++---- pyproject.toml | 14 +++++------ tests/conftest.py | 2 +- tests/{period => interval}/__init__.py | 0 .../{period => interval}/test_add_subtract.py | 0 tests/{period => interval}/test_arithmetic.py | 12 ++++----- tests/{period => interval}/test_behavior.py | 6 ++--- tests/{period => interval}/test_construct.py | 16 ++++++------ tests/{period => interval}/test_hashing.py | 0 tests/{period => interval}/test_in_words.py | 20 ++++++++------- tests/{period => interval}/test_range.py | 22 ++++++++-------- tests/test_parsing.py | 6 ++--- 16 files changed, 85 insertions(+), 84 deletions(-) rename pendulum/{period.py => interval.py} (96%) rename tests/{period => interval}/__init__.py (100%) rename tests/{period => interval}/test_add_subtract.py (100%) rename tests/{period => interval}/test_arithmetic.py (86%) rename tests/{period => interval}/test_behavior.py (89%) rename tests/{period => interval}/test_construct.py (91%) rename tests/{period => interval}/test_hashing.py (100%) rename tests/{period => interval}/test_in_words.py (75%) rename tests/{period => interval}/test_range.py (88%) diff --git a/pendulum/__init__.py b/pendulum/__init__.py index c2e7fc6f..fe5d5d61 100644 --- a/pendulum/__init__.py +++ b/pendulum/__init__.py @@ -33,8 +33,8 @@ from pendulum.helpers import set_locale from pendulum.helpers import week_ends_at from pendulum.helpers import week_starts_at +from pendulum.interval import Interval from pendulum.parser import parse -from pendulum.period import Period from pendulum.testing.traveller import Traveller from pendulum.time import Time from pendulum.tz import UTC @@ -286,11 +286,11 @@ def duration( ) -def period(start: DateTime, end: DateTime, absolute: bool = False) -> Period: +def interval(start: DateTime, end: DateTime, absolute: bool = False) -> Interval: """ Create a Period instance. """ - return Period(start, end, absolute=absolute) + return Interval(start, end, absolute=absolute) # Testing @@ -334,16 +334,16 @@ def period(start: DateTime, end: DateTime, absolute: bool = False) -> Period: "from_timestamp", "get_locale", "instance", + "interval", "local", "locale", "naive", "now", - "period", "set_locale", "week_ends_at", "week_starts_at", "parse", - "Period", + "Interval", "Time", "UTC", "local_timezone", diff --git a/pendulum/date.py b/pendulum/date.py index 65dc1177..60258a73 100644 --- a/pendulum/date.py +++ b/pendulum/date.py @@ -24,8 +24,8 @@ from pendulum.constants import YEARS_PER_DECADE from pendulum.exceptions import PendulumException from pendulum.helpers import add_duration +from pendulum.interval import Interval from pendulum.mixins.default import FormattableMixin -from pendulum.period import Period class Date(FormattableMixin, date): @@ -267,10 +267,10 @@ def __sub__(self, dt: datetime) -> NoReturn: ... @overload - def __sub__(self, dt: Date) -> Period: + def __sub__(self, dt: Date) -> Interval: ... - def __sub__(self, other: timedelta | date) -> Date | Period: + def __sub__(self, other: timedelta | date) -> Date | Interval: if isinstance(other, timedelta): return self._subtract_timedelta(other) @@ -283,7 +283,7 @@ def __sub__(self, other: timedelta | date) -> Date | Period: # DIFFERENCES - def diff(self, dt: date | None = None, abs: bool = True) -> Period: + def diff(self, dt: date | None = None, abs: bool = True) -> Interval: """ Returns the difference between two Date objects as a Period. @@ -293,7 +293,7 @@ def diff(self, dt: date | None = None, abs: bool = True) -> Period: if dt is None: dt = self.today() - return Period(self, Date(dt.year, dt.month, dt.day), absolute=abs) + return Interval(self, Date(dt.year, dt.month, dt.day), absolute=abs) def diff_for_humans( self, diff --git a/pendulum/datetime.py b/pendulum/datetime.py index bb8b4bc8..52ad3cc7 100644 --- a/pendulum/datetime.py +++ b/pendulum/datetime.py @@ -32,7 +32,7 @@ from pendulum.date import Date from pendulum.exceptions import PendulumException from pendulum.helpers import add_duration -from pendulum.period import Period +from pendulum.interval import Interval from pendulum.time import Time from pendulum.tz import UTC from pendulum.tz import local_timezone @@ -645,7 +645,7 @@ def _add_timedelta_(self, delta: datetime.timedelta) -> DateTime: """ Add timedelta duration to the instance. """ - if isinstance(delta, pendulum.Period): + if isinstance(delta, pendulum.Interval): return self.add( years=delta.years, months=delta.months, @@ -678,14 +678,14 @@ def _subtract_timedelta(self, delta: datetime.timedelta) -> DateTime: def diff( # type: ignore[override] self, dt: datetime.datetime | None = None, abs: bool = True - ) -> Period: + ) -> Interval: """ - Returns the difference between two DateTime objects represented as a Period. + Returns the difference between two DateTime objects represented as an Interval. """ if dt is None: dt = self.now(self.tz) - return Period(self, dt, absolute=abs) + return Interval(self, dt, absolute=abs) def diff_for_humans( # type: ignore[override] self, @@ -1170,12 +1170,12 @@ def __sub__(self, other: datetime.timedelta) -> DateTime: ... @overload - def __sub__(self, other: DateTime) -> Period: + def __sub__(self, other: DateTime) -> Interval: ... def __sub__( self, other: datetime.datetime | datetime.timedelta - ) -> DateTime | Period: + ) -> DateTime | Interval: if isinstance(other, datetime.timedelta): return self._subtract_timedelta(other) @@ -1198,7 +1198,7 @@ def __sub__( return other.diff(self, False) - def __rsub__(self, other: datetime.datetime) -> Period: + def __rsub__(self, other: datetime.datetime) -> Interval: if not isinstance(other, datetime.datetime): return NotImplemented diff --git a/pendulum/period.py b/pendulum/interval.py similarity index 96% rename from pendulum/period.py rename to pendulum/interval.py index eb1b232a..f20042bf 100644 --- a/pendulum/period.py +++ b/pendulum/interval.py @@ -24,10 +24,9 @@ from pendulum.locales.locale import Locale # noqa -class Period(Duration): +class Interval(Duration): """ - Duration class that is aware of the datetimes that generated the - time difference. + A period of time between two datetimes. """ @overload @@ -36,7 +35,7 @@ def __new__( start: pendulum.DateTime | datetime, end: pendulum.DateTime | datetime, absolute: bool = False, - ) -> Period: + ) -> Interval: ... @overload @@ -45,7 +44,7 @@ def __new__( start: pendulum.Date | date, end: pendulum.Date | date, absolute: bool = False, - ) -> Period: + ) -> Interval: ... def __new__( @@ -53,7 +52,7 @@ def __new__( start: pendulum.DateTime | pendulum.Date | datetime | date, end: pendulum.DateTime | pendulum.Date | datetime | date, absolute: bool = False, - ) -> Period: + ) -> Interval: if ( isinstance(start, datetime) and not isinstance(end, datetime) @@ -126,7 +125,7 @@ def __new__( delta: timedelta = _end - _start # type: ignore[operator] - return cast(Period, super().__new__(cls, seconds=delta.total_seconds())) + return cast(Interval, super().__new__(cls, seconds=delta.total_seconds())) def __init__( self, @@ -339,7 +338,7 @@ def __add__(self, other: timedelta) -> Duration: def __sub__(self, other: timedelta) -> Duration: return self.as_interval().__sub__(other) - def __neg__(self) -> Period: + def __neg__(self) -> Interval: return self.__class__(self.end, self.start, self._absolute) def __mul__(self, other: int | float) -> Duration: @@ -377,7 +376,7 @@ def __mod__(self, other: timedelta) -> Duration: def __divmod__(self, other: timedelta) -> tuple[int, Duration]: return self.as_interval().__divmod__(other) - def __abs__(self) -> Period: + def __abs__(self) -> Interval: return self.__class__(self.start, self.end, absolute=True) def __repr__(self) -> str: @@ -390,7 +389,7 @@ def _cmp(self, other: timedelta) -> int: # Only needed for PyPy assert isinstance(other, timedelta) - if isinstance(other, Period): + if isinstance(other, Interval): other = other.as_timedelta() td = self.as_timedelta() @@ -414,7 +413,7 @@ def _getstate( def __reduce__( self, ) -> tuple[ - type[Period], + type[Interval], tuple[ pendulum.DateTime | pendulum.Date | datetime | date, pendulum.DateTime | pendulum.Date | datetime | date, @@ -426,7 +425,7 @@ def __reduce__( def __reduce_ex__( self, protocol: SupportsIndex ) -> tuple[ - type[Period], + type[Interval], tuple[ pendulum.DateTime | pendulum.Date | datetime | date, pendulum.DateTime | pendulum.Date | datetime | date, @@ -439,7 +438,7 @@ def __hash__(self) -> int: return hash((self.start, self.end, self._absolute)) def __eq__(self, other: object) -> bool: - if isinstance(other, Period): + if isinstance(other, Interval): return (self.start, self.end, self._absolute) == ( other.start, other.end, diff --git a/pendulum/parser.py b/pendulum/parser.py index f78da263..77900e20 100644 --- a/pendulum/parser.py +++ b/pendulum/parser.py @@ -13,7 +13,7 @@ from pendulum.date import Date from pendulum.datetime import DateTime from pendulum.duration import Duration - from pendulum.period import Period + from pendulum.interval import Interval from pendulum.time import Time try: @@ -29,7 +29,7 @@ def parse(text: str, **options: t.Any) -> Date | Time | DateTime | Duration: return _parse(text, **options) -def _parse(text: str, **options: t.Any) -> Date | DateTime | Time | Duration | Period: +def _parse(text: str, **options: t.Any) -> Date | DateTime | Time | Duration | Interval: """ Parses a string with the given options. @@ -68,7 +68,7 @@ def _parse(text: str, **options: t.Any) -> Date | DateTime | Time | Duration | P if parsed.start is not None: dt = pendulum.instance(parsed.start, tz=options.get("tz", UTC)) - return pendulum.period( + return pendulum.interval( dt, dt.add( years=duration.years, @@ -86,7 +86,7 @@ def _parse(text: str, **options: t.Any) -> Date | DateTime | Time | Duration | P t.cast(datetime.datetime, parsed.end), tz=options.get("tz", UTC) ) - return pendulum.period( + return pendulum.interval( dt.subtract( years=duration.years, months=duration.months, @@ -100,7 +100,7 @@ def _parse(text: str, **options: t.Any) -> Date | DateTime | Time | Duration | P dt, ) - return pendulum.period( + return pendulum.interval( pendulum.instance( t.cast(datetime.datetime, parsed.start), tz=options.get("tz", UTC) ), diff --git a/pyproject.toml b/pyproject.toml index 53ec9906..b17a2a22 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -147,13 +147,13 @@ module = [ "tests.parsing.test_parsing", "tests.parsing.test_parsing_duration", "tests.parsing.test_parse_iso8601", - "tests.period.test_add_subtract", - "tests.period.test_arithmetic", - "tests.period.test_behavior", - "tests.period.test_construct", - "tests.period.test_hashing", - "tests.period.test_in_words", - "tests.period.test_range", + "tests.interval.test_add_subtract", + "tests.interval.test_arithmetic", + "tests.interval.test_behavior", + "tests.interval.test_construct", + "tests.interval.test_hashing", + "tests.interval.test_in_words", + "tests.interval.test_range", "tests.time.test_add", "tests.time.test_behavior", "tests.time.test_comparison", diff --git a/tests/conftest.py b/tests/conftest.py index 9996cc3e..060e9518 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -62,7 +62,7 @@ def assert_duration( minutes=None, seconds=None, microseconds=None, -): +) -> None: expected = {} actual = {} diff --git a/tests/period/__init__.py b/tests/interval/__init__.py similarity index 100% rename from tests/period/__init__.py rename to tests/interval/__init__.py diff --git a/tests/period/test_add_subtract.py b/tests/interval/test_add_subtract.py similarity index 100% rename from tests/period/test_add_subtract.py rename to tests/interval/test_add_subtract.py diff --git a/tests/period/test_arithmetic.py b/tests/interval/test_arithmetic.py similarity index 86% rename from tests/period/test_arithmetic.py rename to tests/interval/test_arithmetic.py index 5b5a8a32..e5ba01f4 100644 --- a/tests/period/test_arithmetic.py +++ b/tests/interval/test_arithmetic.py @@ -8,14 +8,14 @@ def test_multiply(): dt1 = pendulum.DateTime(2016, 8, 7, 12, 34, 56) dt2 = dt1.add(days=6, seconds=34) - it = pendulum.period(dt1, dt2) + it = pendulum.interval(dt1, dt2) mul = it * 2 assert isinstance(mul, pendulum.Duration) assert_duration(mul, 0, 0, 1, 5, 0, 1, 8) dt1 = pendulum.DateTime(2016, 8, 7, 12, 34, 56) dt2 = dt1.add(days=6, seconds=34) - it = pendulum.period(dt1, dt2) + it = pendulum.interval(dt1, dt2) mul = it * 2 assert isinstance(mul, pendulum.Duration) assert_duration(mul, 0, 0, 1, 5, 0, 1, 8) @@ -24,14 +24,14 @@ def test_multiply(): def test_divide(): dt1 = pendulum.DateTime(2016, 8, 7, 12, 34, 56) dt2 = dt1.add(days=2, seconds=34) - it = pendulum.period(dt1, dt2) + it = pendulum.interval(dt1, dt2) mul = it / 2 assert isinstance(mul, pendulum.Duration) assert_duration(mul, 0, 0, 0, 1, 0, 0, 17) dt1 = pendulum.DateTime(2016, 8, 7, 12, 34, 56) dt2 = dt1.add(days=2, seconds=35) - it = pendulum.period(dt1, dt2) + it = pendulum.interval(dt1, dt2) mul = it / 2 assert isinstance(mul, pendulum.Duration) assert_duration(mul, 0, 0, 0, 1, 0, 0, 17) @@ -40,14 +40,14 @@ def test_divide(): def test_floor_divide(): dt1 = pendulum.DateTime(2016, 8, 7, 12, 34, 56) dt2 = dt1.add(days=2, seconds=34) - it = pendulum.period(dt1, dt2) + it = pendulum.interval(dt1, dt2) mul = it // 2 assert isinstance(mul, pendulum.Duration) assert_duration(mul, 0, 0, 0, 1, 0, 0, 17) dt1 = pendulum.DateTime(2016, 8, 7, 12, 34, 56) dt2 = dt1.add(days=2, seconds=35) - it = pendulum.period(dt1, dt2) + it = pendulum.interval(dt1, dt2) mul = it // 3 assert isinstance(mul, pendulum.Duration) assert_duration(mul, 0, 0, 0, 0, 16, 0, 11) diff --git a/tests/period/test_behavior.py b/tests/interval/test_behavior.py similarity index 89% rename from tests/period/test_behavior.py rename to tests/interval/test_behavior.py index 98cf2494..b5e057a7 100644 --- a/tests/period/test_behavior.py +++ b/tests/interval/test_behavior.py @@ -11,7 +11,7 @@ def test_pickle(): dt1 = pendulum.datetime(2016, 11, 18) dt2 = pendulum.datetime(2016, 11, 20) - p = pendulum.period(dt1, dt2) + p = pendulum.interval(dt1, dt2) s = pickle.dumps(p) p2 = pickle.loads(s) @@ -19,7 +19,7 @@ def test_pickle(): assert p.end == p2.end assert p.invert == p2.invert - p = pendulum.period(dt2, dt1) + p = pendulum.interval(dt2, dt1) s = pickle.dumps(p) p2 = pickle.loads(s) @@ -27,7 +27,7 @@ def test_pickle(): assert p.end == p2.end assert p.invert == p2.invert - p = pendulum.period(dt2, dt1, True) + p = pendulum.interval(dt2, dt1, True) s = pickle.dumps(p) p2 = pickle.loads(s) diff --git a/tests/period/test_construct.py b/tests/interval/test_construct.py similarity index 91% rename from tests/period/test_construct.py rename to tests/interval/test_construct.py index 91374b5f..024e7412 100644 --- a/tests/period/test_construct.py +++ b/tests/interval/test_construct.py @@ -10,7 +10,7 @@ def test_with_datetimes(): dt1 = datetime(2000, 1, 1) dt2 = datetime(2000, 1, 31) - p = pendulum.period(dt1, dt2) + p = pendulum.interval(dt1, dt2) assert isinstance(p.start, pendulum.DateTime) assert isinstance(p.end, pendulum.DateTime) @@ -21,7 +21,7 @@ def test_with_datetimes(): def test_with_pendulum(): dt1 = pendulum.DateTime(2000, 1, 1) dt2 = pendulum.DateTime(2000, 1, 31) - p = pendulum.period(dt1, dt2) + p = pendulum.interval(dt1, dt2) assert_datetime(p.start, 2000, 1, 1) assert_datetime(p.end, 2000, 1, 31) @@ -30,7 +30,7 @@ def test_with_pendulum(): def test_inverted(): dt1 = pendulum.DateTime(2000, 1, 1) dt2 = pendulum.DateTime(2000, 1, 31) - p = pendulum.period(dt2, dt1) + p = pendulum.interval(dt2, dt1) assert_datetime(p.start, 2000, 1, 31) assert_datetime(p.end, 2000, 1, 1) @@ -39,7 +39,7 @@ def test_inverted(): def test_inverted_and_absolute(): dt1 = pendulum.DateTime(2000, 1, 1) dt2 = pendulum.DateTime(2000, 1, 31) - p = pendulum.period(dt2, dt1, True) + p = pendulum.interval(dt2, dt1, True) assert_datetime(p.start, 2000, 1, 1) assert_datetime(p.end, 2000, 1, 31) @@ -49,8 +49,8 @@ def test_accuracy(): dt1 = pendulum.DateTime(2000, 11, 20) dt2 = pendulum.DateTime(2000, 11, 25) dt3 = pendulum.DateTime(2016, 11, 5) - p1 = pendulum.period(dt1, dt3) - p2 = pendulum.period(dt2, dt3) + p1 = pendulum.interval(dt1, dt3) + p2 = pendulum.interval(dt2, dt3) assert p1.years == 15 assert p1.in_years() == 15 @@ -90,8 +90,8 @@ def test_timedelta_behavior(): dt2 = pendulum.DateTime(2000, 11, 25, 2) dt3 = pendulum.DateTime(2016, 11, 5, 3) - p1 = pendulum.period(dt1, dt3) - p2 = pendulum.period(dt2, dt3) + p1 = pendulum.interval(dt1, dt3) + p2 = pendulum.interval(dt2, dt3) it1 = p1.as_timedelta() it2 = p2.as_timedelta() diff --git a/tests/period/test_hashing.py b/tests/interval/test_hashing.py similarity index 100% rename from tests/period/test_hashing.py rename to tests/interval/test_hashing.py diff --git a/tests/period/test_in_words.py b/tests/interval/test_in_words.py similarity index 75% rename from tests/period/test_in_words.py rename to tests/interval/test_in_words.py index a6e8fb2a..410e11f2 100644 --- a/tests/period/test_in_words.py +++ b/tests/interval/test_in_words.py @@ -5,19 +5,19 @@ def test_week(): start_date = pendulum.datetime(2012, 1, 1) - period = pendulum.period(start=start_date, end=start_date.add(weeks=1)) + period = pendulum.interval(start=start_date, end=start_date.add(weeks=1)) assert period.in_words() == "1 week" def test_week_and_day(): start_date = pendulum.datetime(2012, 1, 1) - period = pendulum.period(start=start_date, end=start_date.add(weeks=1, days=1)) + period = pendulum.interval(start=start_date, end=start_date.add(weeks=1, days=1)) assert period.in_words() == "1 week 1 day" def test_all(): start_date = pendulum.datetime(2012, 1, 1) - period = pendulum.period( + period = pendulum.interval( start=start_date, end=start_date.add(years=1, months=1, days=1, seconds=1, microseconds=1), ) @@ -26,7 +26,7 @@ def test_all(): def test_in_french(): start_date = pendulum.datetime(2012, 1, 1) - period = pendulum.period( + period = pendulum.interval( start=start_date, end=start_date.add(years=1, months=1, days=1, seconds=1, microseconds=1), ) @@ -35,13 +35,13 @@ def test_in_french(): def test_singular_negative_values(): start_date = pendulum.datetime(2012, 1, 1) - period = pendulum.period(start=start_date, end=start_date.subtract(days=1)) + period = pendulum.interval(start=start_date, end=start_date.subtract(days=1)) assert period.in_words() == "-1 day" def test_separator(): start_date = pendulum.datetime(2012, 1, 1) - period = pendulum.period( + period = pendulum.interval( start=start_date, end=start_date.add(years=1, months=1, days=1, seconds=1, microseconds=1), ) @@ -50,13 +50,15 @@ def test_separator(): def test_subseconds(): start_date = pendulum.datetime(2012, 1, 1) - period = pendulum.period(start=start_date, end=start_date.add(microseconds=123456)) + period = pendulum.interval( + start=start_date, end=start_date.add(microseconds=123456) + ) assert period.in_words() == "0.12 second" def test_subseconds_with_seconds(): start_date = pendulum.datetime(2012, 1, 1) - period = pendulum.period( + period = pendulum.interval( start=start_date, end=start_date.add(seconds=12, microseconds=123456) ) assert period.in_words() == "12 seconds" @@ -64,5 +66,5 @@ def test_subseconds_with_seconds(): def test_zero_period(): start_date = pendulum.datetime(2012, 1, 1) - period = pendulum.period(start=start_date, end=start_date) + period = pendulum.interval(start=start_date, end=start_date) assert period.in_words() == "0 microseconds" diff --git a/tests/period/test_range.py b/tests/interval/test_range.py similarity index 88% rename from tests/period/test_range.py rename to tests/interval/test_range.py index 46c4e760..28fe1ff8 100644 --- a/tests/period/test_range.py +++ b/tests/interval/test_range.py @@ -2,7 +2,7 @@ import pendulum -from pendulum import Period +from pendulum.interval import Interval from tests.conftest import assert_datetime @@ -10,7 +10,7 @@ def test_range(): dt1 = pendulum.datetime(2000, 1, 1, 12, 45, 37) dt2 = pendulum.datetime(2000, 1, 31, 12, 45, 37) - p = Period(dt1, dt2) + p = Interval(dt1, dt2) r = list(p.range("days")) assert len(r) == 31 @@ -22,7 +22,7 @@ def test_range_no_overflow(): dt1 = pendulum.datetime(2000, 1, 1, 12, 45, 37) dt2 = pendulum.datetime(2000, 1, 31, 11, 45, 37) - p = Period(dt1, dt2) + p = Interval(dt1, dt2) r = list(p.range("days")) assert len(r) == 30 @@ -34,7 +34,7 @@ def test_range_inverted(): dt1 = pendulum.datetime(2000, 1, 1, 12, 45, 37) dt2 = pendulum.datetime(2000, 1, 31, 12, 45, 37) - p = Period(dt2, dt1) + p = Interval(dt2, dt1) r = list(p.range("days")) assert len(r) == 31 @@ -46,7 +46,7 @@ def test_iter(): dt1 = pendulum.datetime(2000, 1, 1, 12, 45, 37) dt2 = pendulum.datetime(2000, 1, 31, 12, 45, 37) - p = Period(dt1, dt2) + p = Interval(dt1, dt2) i = 0 # noqa: SIM113 (suggests use of enumerate) for dt in p: assert isinstance(dt, pendulum.DateTime) @@ -59,7 +59,7 @@ def test_contains(): dt1 = pendulum.datetime(2000, 1, 1, 12, 45, 37) dt2 = pendulum.datetime(2000, 1, 31, 12, 45, 37) - p = pendulum.period(dt1, dt2) + p = pendulum.interval(dt1, dt2) dt = pendulum.datetime(2000, 1, 7) assert dt in p @@ -68,7 +68,7 @@ def test_not_contains(): dt1 = pendulum.datetime(2000, 1, 1, 12, 45, 37) dt2 = pendulum.datetime(2000, 1, 31, 12, 45, 37) - p = pendulum.period(dt1, dt2) + p = pendulum.interval(dt1, dt2) dt = pendulum.datetime(2000, 1, 1, 11, 45, 37) assert dt not in p @@ -77,7 +77,7 @@ def test_contains_with_datetime(): dt1 = pendulum.datetime(2000, 1, 1, 12, 45, 37) dt2 = pendulum.datetime(2000, 1, 31, 12, 45, 37) - p = pendulum.period(dt1, dt2) + p = pendulum.interval(dt1, dt2) dt = pendulum.datetime(2000, 1, 7) assert dt in p @@ -86,7 +86,7 @@ def test_range_months_overflow(): dt1 = pendulum.datetime(2016, 1, 30, tz="America/Sao_Paulo") dt2 = dt1.add(months=4) - p = pendulum.period(dt1, dt2) + p = pendulum.interval(dt1, dt2) r = list(p.range("months")) assert_datetime(r[0], 2016, 1, 30, 0, 0, 0) @@ -97,7 +97,7 @@ def test_range_with_dst(): dt1 = pendulum.datetime(2016, 10, 14, tz="America/Sao_Paulo") dt2 = dt1.add(weeks=1) - p = pendulum.period(dt1, dt2) + p = pendulum.interval(dt1, dt2) r = list(p.range("days")) assert_datetime(r[0], 2016, 10, 14, 0, 0, 0) @@ -109,7 +109,7 @@ def test_range_amount(): dt1 = pendulum.datetime(2016, 10, 14, tz="America/Sao_Paulo") dt2 = dt1.add(weeks=1) - p = pendulum.period(dt1, dt2) + p = pendulum.interval(dt1, dt2) r = list(p.range("days", 2)) assert len(r) == 4 diff --git a/tests/test_parsing.py b/tests/test_parsing.py index 8890e23f..0e5308c8 100644 --- a/tests/test_parsing.py +++ b/tests/test_parsing.py @@ -97,7 +97,7 @@ def test_parse_interval(): period = pendulum.parse(text) - assert isinstance(period, pendulum.Period) + assert isinstance(period, pendulum.Interval) assert_datetime(period.start, 2008, 5, 11, 15, 30, 0, 0) assert period.start.offset == 0 assert_datetime(period.end, 2009, 7, 21, 18, 0, 0, 0) @@ -107,7 +107,7 @@ def test_parse_interval(): period = pendulum.parse(text) - assert isinstance(period, pendulum.Period) + assert isinstance(period, pendulum.Interval) assert_datetime(period.start, 2007, 3, 1, 13, 0, 0, 0) assert period.start.offset == 0 assert_datetime(period.end, 2008, 5, 11, 15, 30, 0, 0) @@ -117,7 +117,7 @@ def test_parse_interval(): period = pendulum.parse(text) - assert isinstance(period, pendulum.Period) + assert isinstance(period, pendulum.Interval) assert_datetime(period.start, 2007, 3, 1, 13, 0, 0, 0) assert period.start.offset == 0 assert_datetime(period.end, 2008, 5, 11, 15, 30, 0, 0)