Skip to content

Commit 991eadf

Browse files
committed
Removes deprecated methods
1 parent 6bca027 commit 991eadf

14 files changed

+142
-423
lines changed

pendulum/__init__.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,6 @@
5454
tomorrow = Pendulum.tomorrow
5555
yesterday = Pendulum.yesterday
5656
create = Pendulum.create
57-
from_date = Pendulum.create_from_date
58-
from_time = Pendulum.create_from_time
5957
from_format = Pendulum.create_from_format
6058
strptime = Pendulum.strptime
6159
from_timestamp = Pendulum.create_from_timestamp

pendulum/interval.py

Lines changed: 1 addition & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
# -*- coding: utf-8 -*-
22

3-
import warnings
43
from datetime import timedelta
54

65
from .mixins.interval import (
@@ -79,53 +78,6 @@ def total_days(self):
7978
def total_weeks(self):
8079
return self.total_days() / 7
8180

82-
def total_months(self):
83-
warnings.warn(
84-
'Interval.total_months() is deprecated. '
85-
'It will be removed in the next major version.',
86-
category=DeprecationWarning,
87-
stacklevel=2
88-
)
89-
return round(self.total_days() / 30.436875, 1)
90-
91-
def total_years(self):
92-
warnings.warn(
93-
'Interval.total_years() is deprecated. '
94-
'It will be removed in the next major version.',
95-
category=DeprecationWarning,
96-
stacklevel=2
97-
)
98-
return round(self.total_days() / 365.2425, 1)
99-
100-
@property
101-
def years(self):
102-
warnings.warn(
103-
'Interval.years is deprecated. '
104-
'It will be removed in the next major version.',
105-
category=DeprecationWarning,
106-
stacklevel=2
107-
)
108-
if self._y is None:
109-
days = self._days
110-
self._y = int(round(abs(days) / 365, 1) * self._sign(days))
111-
112-
return self._y
113-
114-
115-
@property
116-
def months(self):
117-
warnings.warn(
118-
'Interval.months is deprecated. '
119-
'It will be removed in the next major version.',
120-
category=DeprecationWarning,
121-
stacklevel=2
122-
)
123-
if self._m is None:
124-
days = self._days
125-
self._m = int(round(abs(days) / 30.436875, 1) % 12 * self._sign(days))
126-
127-
return self._m
128-
12981
@property
13082
def weeks(self):
13183
return abs(self.days) // 7 * self._sign(self._days)
@@ -134,20 +86,9 @@ def weeks(self):
13486
def days(self):
13587
return self._days
13688

137-
@property
138-
def days_exclude_weeks(self):
139-
warnings.warn(
140-
'Interval.days_exclude_weeks is deprecated. '
141-
'It will be removed in the next major version. '
142-
'Use Interval.remaing_days instead.',
143-
category=DeprecationWarning,
144-
stacklevel=2
145-
)
146-
return abs(self._days) % 7 * self._sign(self._days)
147-
14889
@property
14990
def remaining_days(self):
150-
return self.days_exclude_weeks
91+
return abs(self._days) % 7 * self._sign(self._days)
15192

15293
@property
15394
def hours(self):
@@ -192,24 +133,6 @@ def invert(self):
192133

193134
return self._invert
194135

195-
def in_years(self):
196-
warnings.warn(
197-
'Interval.in_years() is deprecated. '
198-
'It will be removed in the next major version.',
199-
category=DeprecationWarning,
200-
stacklevel=2
201-
)
202-
return int(self.total_years())
203-
204-
def in_months(self):
205-
warnings.warn(
206-
'Interval.in_months() is deprecated. '
207-
'It will be removed in the next major version.',
208-
category=DeprecationWarning,
209-
stacklevel=2
210-
)
211-
return int(self.total_months())
212-
213136
def in_weeks(self):
214137
return int(self.total_weeks())
215138

pendulum/pendulum.py

Lines changed: 1 addition & 107 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
import calendar
66
import datetime
7-
import warnings
87

98
from .date import Date
109
from .time import Time
@@ -20,7 +19,6 @@
2019
MINUTES_PER_HOUR, SECONDS_PER_MINUTE,
2120
SECONDS_PER_DAY
2221
)
23-
from .utils import CallableTimestamp
2422

2523

2624
class Pendulum(Date, datetime.datetime):
@@ -378,57 +376,6 @@ def create(cls, year=None, month=None, day=None,
378376

379377
return cls.instance(dt, tz)
380378

381-
@classmethod
382-
def create_from_date(cls, year=None, month=None, day=None, tz='UTC'):
383-
"""
384-
Create a Pendulum instance from just a date.
385-
The time portion is set to 00:00:00.
386-
387-
:type year: int
388-
:type month: int
389-
:type day: int
390-
:type tz: tzinfo or str or None
391-
392-
:rtype: Pendulum
393-
"""
394-
warnings.warn(
395-
'create_from_date() is deprecated. '
396-
'It will be removed in the next major version. '
397-
'Use create(year, month, day) instead.',
398-
category=DeprecationWarning,
399-
stacklevel=2
400-
)
401-
402-
return cls.create(year, month, day, tz=tz)
403-
404-
@classmethod
405-
def create_from_time(cls, hour=0, minute=0, second=0,
406-
microsecond=0, tz='UTC'):
407-
"""
408-
Create a Pendulum instance from just a time.
409-
The date portion is set to today.
410-
411-
:type hour: int
412-
:type minute: int
413-
:type second: int
414-
:type microsecond: int
415-
:type tz: tzinfo or str or int or None
416-
417-
:rtype: Pendulum
418-
"""
419-
warnings.warn(
420-
'create_from_time() is deprecated. '
421-
'It will be removed in the next major version. '
422-
'Use create(hour=hour, minute=minute, second=second) instead.',
423-
category=DeprecationWarning,
424-
stacklevel=2
425-
)
426-
427-
return cls.now(tz).replace(
428-
hour=hour, minute=minute, second=second,
429-
microsecond=microsecond
430-
)
431-
432379
@classmethod
433380
def create_from_format(cls, time, fmt, tz=UTC):
434381
"""
@@ -554,15 +501,11 @@ def tzinfo(self):
554501
def fold(self):
555502
return self._fold
556503

557-
@property
558504
def timestamp(self):
559505
if self._timestamp is None:
560506
delta = self._datetime - self._EPOCH
561507

562-
self._timestamp = CallableTimestamp(
563-
delta.days * SECONDS_PER_DAY + delta.seconds
564-
)
565-
self._timestamp.set_float(delta.total_seconds())
508+
self._timestamp = delta.total_seconds()
566509

567510
return self._timestamp
568511

@@ -648,29 +591,6 @@ def on(self, year, month, day):
648591
year=int(year), month=int(month), day=int(day)
649592
)
650593

651-
def with_date(self, year, month, day):
652-
"""
653-
Returns a new instance with the current date set to a different date.
654-
655-
:param year: The year
656-
:type year: int
657-
658-
:param month: The month
659-
:type month: int
660-
661-
:param day: The day
662-
:type day: int
663-
664-
:rtype: Pendulum
665-
"""
666-
warnings.warn(
667-
'with_date() is deprecated. Use on() instead.',
668-
category=DeprecationWarning,
669-
stacklevel=2
670-
)
671-
672-
return self.on(year, month, day)
673-
674594
def at(self, hour, minute, second, microsecond=0):
675595
"""
676596
Returns a new instance with the current time to a different time.
@@ -694,32 +614,6 @@ def at(self, hour, minute, second, microsecond=0):
694614
microsecond=microsecond
695615
)
696616

697-
def with_time(self, hour, minute, second, microsecond=0):
698-
"""
699-
Returns a new instance with the current time set to a different time.
700-
701-
:param hour: The hour
702-
:type hour: int
703-
704-
:param minute: The minute
705-
:type minute: int
706-
707-
:param second: The second
708-
:type second: int
709-
710-
:param microsecond: The microsecond
711-
:type microsecond: int
712-
713-
:rtype: Pendulum
714-
"""
715-
warnings.warn(
716-
'with_time() is deprecated. Use at() instead.',
717-
category=DeprecationWarning,
718-
stacklevel=2
719-
)
720-
721-
return self.at(hour, minute, second, microsecond)
722-
723617
def with_date_time(self, year, month, day, hour, minute, second, microsecond=0):
724618
"""
725619
Return a new instance with the date and time set to the given values.

pendulum/time.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ def add(self, hours=0, minutes=0, seconds=0, microseconds=0):
252252
"""
253253
from .pendulum import Pendulum
254254

255-
return Pendulum.EPOCH.with_time(
255+
return Pendulum.EPOCH.at(
256256
self._hour, self._minute, self._second, self._microsecond
257257
).add(
258258
hours=hours,
@@ -281,7 +281,7 @@ def subtract(self, hours=0, minutes=0, seconds=0, microseconds=0):
281281
"""
282282
from .pendulum import Pendulum
283283

284-
return Pendulum.EPOCH.with_time(
284+
return Pendulum.EPOCH.at(
285285
self._hour, self._minute, self._second, self._microsecond
286286
).subtract(
287287
hours=hours,

pendulum/utils.py

Lines changed: 0 additions & 24 deletions
This file was deleted.

tests/interval_tests/test_in_methods.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,6 @@
77

88
class InMethodsTest(AbstractTestCase):
99

10-
def test_in_years(self):
11-
it = Interval(days=365)
12-
self.assertEqual(1, it.in_years())
13-
14-
def test_in_months(self):
15-
it = Interval(days=75)
16-
self.assertEqual(2, it.in_months())
17-
1810
def test_in_weeks(self):
1911
it = Interval(days=17)
2012
self.assertEqual(2, it.in_weeks())

tests/interval_tests/test_total_methods.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,6 @@
77

88
class TotalMethodsTest(AbstractTestCase):
99

10-
def test_total_years(self):
11-
it = Interval(days=365)
12-
self.assertEqual(1, it.total_years())
13-
14-
def test_in_months(self):
15-
it = Interval(days=75)
16-
self.assertEqual(2.5, it.total_months())
17-
1810
def test_in_weeks(self):
1911
it = Interval(days=17)
2012
self.assertEqual(2.43, round(it.total_weeks(), 2))

tests/pendulum_tests/test_create_from_date.py

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,41 +8,37 @@
88
class CreateFromDateTest(AbstractTestCase):
99

1010
def test_create_from_date_with_defaults(self):
11-
d = Pendulum.create_from_date()
12-
self.assertEqual(d.timestamp, Pendulum.utcnow().with_time(0, 0, 0, 0).timestamp)
11+
d = Pendulum.create()
12+
self.assertEqual(d.timestamp, Pendulum.utcnow().at(0, 0, 0, 0).timestamp)
1313

1414
def test_create_from_date(self):
15-
d = Pendulum.create_from_date(1975, 12, 25)
15+
d = Pendulum.create(1975, 12, 25)
1616
self.assertPendulum(d, 1975, 12, 25, 0, 0, 0)
1717

1818
def test_create_from_date_with_year(self):
19-
d = Pendulum.create_from_date(1975)
19+
d = Pendulum.create(1975)
2020
self.assertEqual(d.year, 1975)
2121

2222
def test_create_from_date_with_month(self):
23-
d = Pendulum.create_from_date(None, 12)
24-
self.assertEqual(d.month, 12)
25-
d = Pendulum.create_from_date(month=12)
23+
d = Pendulum.create(month=12)
2624
self.assertEqual(d.month, 12)
2725

2826
def test_create_from_date_with_day(self):
29-
d = Pendulum.create_from_date(None, None, 25)
30-
self.assertEqual(d.day, 25)
31-
d = Pendulum.create_from_date(day=25)
27+
d = Pendulum.create(day=25)
3228
self.assertEqual(d.day, 25)
3329

3430
def test_create_from_date_with_timezone_string(self):
35-
d = Pendulum.create_from_date(1975, 12, 25, tz='Europe/London')
31+
d = Pendulum.create(1975, 12, 25, tz='Europe/London')
3632
self.assertPendulum(d, 1975, 12, 25)
3733
self.assertEqual('Europe/London', d.timezone_name)
3834

3935
def test_create_from_date_with_timezone(self):
40-
d = Pendulum.create_from_date(1975, 12, 25, tz=timezone('Europe/London'))
36+
d = Pendulum.create(1975, 12, 25, tz=timezone('Europe/London'))
4137
self.assertPendulum(d, 1975, 12, 25)
4238
self.assertEqual('Europe/London', d.timezone_name)
4339

4440
def test_create_from_date_with_tzinfo(self):
4541
tz = timezone('Europe/London')
46-
d = Pendulum.create_from_date(1975, 12, 25, tz=TimezoneInfo(tz, 3600, True, None, ''))
42+
d = Pendulum.create(1975, 12, 25, tz=TimezoneInfo(tz, 3600, True, None, ''))
4743
self.assertPendulum(d, 1975, 12, 25)
4844
self.assertEqual('Europe/London', d.timezone_name)

0 commit comments

Comments
 (0)