Skip to content

Commit 58ffabd

Browse files
committed
Add deprecation warnings for methods that will no longer be supported in pendulum 2.0
1 parent 894d002 commit 58ffabd

23 files changed

+560
-151
lines changed

CHANGELOG.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,25 @@
11
# Change Log
22

3+
## [Unreleased]
4+
5+
### Added
6+
7+
- Added the `set()` method to set properties.
8+
- Added the `is_utc()` and `is_local()` methods.
9+
10+
### Deprecated
11+
12+
- `year_()`, `month_()`, `day_`, `hour_`, `minute_`, `second_`, `microsecond_()` are now deprecated.
13+
- `timezone_()` and `tz_()` are now deprecated.
14+
- `timestamp_()` is now deprecated.
15+
- `with_date_time()`, `with_time_from_string()` and `with_timestamp()` are now deprecated.
16+
- `between()` is now deprecated.
17+
- `min_()`, `max_()`, `minimum()`, `maximum()` are now deprecated.
18+
- `is_today()`, `is_yesterday()`, `is_tomorrow()` and `is_same_day()` are now depecreated.
19+
- `is_sunday()` -> `is_saturday()` are now deprecated.
20+
- The `utc` and `local` properties are now deprecated. Use `is_utc()` and `is_local()` instead.
21+
22+
323
## [1.4.4] - 2018-03-21
424

525
### Fixed

docs/_docs/addition_subtraction.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Each method returns a new ``Pendulum`` instance.
99
1010
import pendulum
1111
12-
dt = pendulum.create(2012, 1, 31, 0)
12+
dt = pendulum.datetime(2012, 1, 31, 0)
1313
1414
dt.to_datetime_string()
1515
'2012-01-31 00:00:00'

docs/_docs/attributes_properties.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ Pendulum gives access to more attributes and properties than the default ``datet
4141
dt.int_timestamp
4242
1346887571
4343
44-
pendulum.create(1975, 5, 21).age
44+
pendulum.datetime(1975, 5, 21).age
4545
41 # calculated vs now in the same tz
4646
dt.quarter
4747
3
@@ -59,9 +59,9 @@ Pendulum gives access to more attributes and properties than the default ``datet
5959
9.5
6060
6161
# Indicates if day light savings time is on
62-
pendulum.create(2012, 1, 1, tz='America/Toronto').is_dst
62+
pendulum.datetime(2012, 1, 1, tz='America/Toronto').is_dst
6363
False
64-
pendulum.create(2012, 9, 1, tz='America/Toronto').is_dst
64+
pendulum.datetime(2012, 9, 1, tz='America/Toronto').is_dst
6565
True
6666
6767
# Indicates if the instance is in the same timezone as the local timezone

docs/_docs/comparison.rst

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ Remember that the comparison is done in the UTC timezone so things aren't always
88
99
import pendulum
1010
11-
first = pendulum.create(2012, 9, 5, 23, 26, 11, 0, tz='America/Toronto')
12-
second = pendulum.create(2012, 9, 5, 20, 26, 11, 0, tz='America/Vancouver')
11+
first = pendulum.datetime(2012, 9, 5, 23, 26, 11, tz='America/Toronto')
12+
second = pendulum.datetime(2012, 9, 5, 20, 26, 11, tz='America/Vancouver')
1313
1414
first.to_datetime_string()
1515
'2012-09-05 23:26:11'
@@ -58,14 +58,14 @@ The default is ``True`` which determines if its between or equal to the boundari
5858
5959
import pendulum
6060
61-
first = pendulum.create(2012, 9, 5, 1)
62-
second = pendulum.create(2012, 9, 5, 5)
61+
first = pendulum.datetime(2012, 9, 5, 1)
62+
second = pendulum.datetime(2012, 9, 5, 5)
6363
64-
pendulum.create(2012, 9, 5, 3).between(first, second)
64+
pendulum.datetime(2012, 9, 5, 3).between(first, second)
6565
True
66-
pendulum.create(2012, 9, 5, 3).between(first, second)
66+
pendulum.datetime(2012, 9, 5, 3).between(first, second)
6767
True
68-
pendulum.create(2012, 9, 5, 5).between(first, second, False)
68+
pendulum.datetime(2012, 9, 5, 5).between(first, second, False)
6969
False
7070
7171
There are also the ``min_()`` and ``max_()`` methods.
@@ -75,8 +75,8 @@ As usual the default parameter is ``now`` if ``None`` is specified.
7575
7676
import pendulum
7777
78-
dt1 = pendulum.create(2012, 1, 1, 0, 0, 0, 0)
79-
dt2 = pendulum.create(2014, 1, 30, 0, 0, 0, 0)
78+
dt1 = pendulum.datetime(2012, 1, 1, 0, 0, 0, 0)
79+
dt2 = pendulum.datetime(2014, 1, 30, 0, 0, 0, 0)
8080
8181
print(dt1.min_(dt2))
8282
'2012-01-01T00:00:00+00:00'
@@ -104,15 +104,9 @@ the ``now()`` is created in the same timezone as the instance.
104104
105105
dt = pendulum.now()
106106
107-
dt.is_weekday()
108-
dt.is_weekend()
109-
dt.is_yesterday()
110-
dt.is_today()
111-
dt.is_tomorrow()
112107
dt.is_future()
113108
dt.is_past()
114109
dt.is_leap_year()
115-
dt.is_same_day(pendulum.now())
116110
117111
born = pendulum.create(1987, 4, 23)
118112
not_birthday = pendulum.create(2014, 9, 26)

docs/_docs/difference.rst

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ This will default to ``True``, return the absolute value. The comparisons are do
1717
1818
import pendulum
1919
20-
dt_ottawa = pendulum.create(2000, 1, 1, tz='America/Toronto')
21-
dt_vancouver = pendulum.create(2000, 1, 1, tz='America/Vancouver')
20+
dt_ottawa = pendulum.datetime(2000, 1, 1, tz='America/Toronto')
21+
dt_vancouver = pendulum.datetime(2000, 1, 1, tz='America/Vancouver')
2222
2323
dt_ottawa.diff(dt_vancouver).in_hours()
2424
3
@@ -27,19 +27,19 @@ This will default to ``True``, return the absolute value. The comparisons are do
2727
dt_vancouver.diff(dt_ottawa, False).in_hours()
2828
-3
2929
30-
dt = pendulum.create(2012, 1, 31, 0)
30+
dt = pendulum.datetime(2012, 1, 31, 0)
3131
dt.diff(dt.add(months=1)).in_days()
3232
29
3333
dt.diff(dt.subtract(months=1), False).in_days()
3434
-31
3535
36-
dt = pendulum.create(2012, 4, 30, 0)
36+
dt = pendulum.datetime(2012, 4, 30, 0)
3737
dt.diff(dt.add(months=1)).in_days()
3838
30
3939
dt.diff(dt.add(weeks=1)).in_days()
4040
7
4141
42-
dt = pendulum.create(2012, 1, 1, 0)
42+
dt = pendulum.datetime(2012, 1, 1, 0)
4343
dt.diff(dt.add(seconds=59)).in_minutes()
4444
0
4545
dt.diff(dt.add(seconds=60)).in_minutes()
@@ -89,7 +89,7 @@ You may also pass ``True`` as a 2nd parameter to remove the modifiers `ago`, `fr
8989
pendulum.now().diff_for_humans(pendulum.now().subtract(years=1))
9090
'1 year after'
9191
92-
dt = pendulum.create(2011, 8, 1)
92+
dt = pendulum.datetime(2011, 8, 1)
9393
dt.diff_for_humans(dt.add(months=1))
9494
'1 month before'
9595
dt.diff_for_humans(dt.subtract(months=1))

docs/_docs/fluent_helpers.rst

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,21 @@ setting the timestamp will not set the corresponding timezone to UTC.
1414
1515
dt = pendulum.now()
1616
17-
dt = dt.year_(1975).month_(5).day_(21).to_datetime_string()
17+
dt = dt.set(year=1975, month=5, day=21).to_datetime_string()
1818
'1975-05-21 13:45:18'
1919
20-
dt.hour_(22).minute_(32).second_(5).to_datetime_string()
20+
dt.set(hour=22, minute=32, second=5).to_datetime_string()
2121
'2016-11-16 22:32:05'
2222
2323
dt.on(1975, 5, 21).at(22, 32, 5).to_datetime_string()
2424
'1975-05-21 22:32:05'
2525
26-
dt.timestamp_(169957925).timezone_('Europe/London')
26+
dt.set(tz='Europe/London')
2727
28-
dt.tz_('America/Toronto').in_timezone('America/Vancouver')
28+
dt.set(tz='America/Toronto').in_timezone('America/Vancouver')
2929
3030
.. note::
3131

32-
``timezone_()`` and ``tz_()`` just modify the timezone information without
32+
``set(tz=...)`` just modify the timezone information without
3333
making any conversion while ``in_timezone()`` converts the time in the
3434
appropriate timezone.

docs/_docs/instantiation.rst

Lines changed: 9 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,19 @@ Instantiation
22
=============
33

44
There are several different methods available to create a new instance of Pendulum.
5-
First there is a constructor. It accepts the same parameters as the standard class.
5+
First there is a the `datetime()` helper.
66

77
.. code-block:: python
88
9-
from pendulum import Pendulum
9+
import pendulum
1010
11-
dt = Pendulum(2015, 2, 5, tzinfo='America/Vancouver')
11+
dt = pendulum.datetime(2015, 2, 5, tz='America/Vancouver')
1212
isinstance(dt, datetime)
1313
True
1414
15-
dt = Pendulum.now(-5)
16-
17-
You'll notice above that the timezone (2nd) parameter was passed as a string and an integer
18-
rather than a ``tzinfo`` instance. All timezone parameters have been augmented
19-
so you can pass a ``tzinfo`` instance, string or integer offset to GMT
20-
and the timezone will be created for you.
15+
`datetime()` sets the time to `00:00:00` if it's not specified,
16+
and the timezone (the `tz` keyword argument) to `UTC`.
17+
It otherwise can be a `Timezone` instance or simply a string timezone value.
2118

2219
.. note::
2320

@@ -44,7 +41,7 @@ and the timezone will be created for you.
4441
'US/Pacific-New',
4542
'US/Samoa')
4643
47-
This is again shown in the next example which also introduces the ``now()`` function.
44+
There is also the ``now()`` helper.
4845

4946
.. code-block:: python
5047
@@ -87,7 +84,7 @@ besides behaving as expected, all accept a timezone parameter and each has their
8784
print(yesterday)
8885
'2016-06-27T00:00:00-05:00'
8986
90-
The next helper is ``create()`` which allows you to provide
87+
The next helper is ``datetime()`` which allows you to provide
9188
as many or as few arguments as you want and will provide default values for all others.
9289

9390
.. code-block:: python
@@ -129,7 +126,7 @@ The difference being the addition the ``tz`` argument that can be a ``tzinfo`` i
129126
130127
Note that it will be the only one supported in the next major version.
131128
132-
The final ``create`` function is for working with unix timestamps.
129+
The final helper is for working with unix timestamps.
133130
``from_timestamp()`` will create a ``Pendulum`` instance equal to the given timestamp
134131
and will set the timezone as well or default it to ``UTC``.
135132

@@ -141,21 +138,6 @@ and will set the timezone as well or default it to ``UTC``.
141138
pendulum.from_timestamp(-1, 'Europe/London').to_datetime_string()
142139
'1970-01-01 00:59:59'
143140
144-
# Using the standard fromtimestamp is also possible
145-
pendulum.fromtimestamp(-1).to_datetime_string()
146-
'1969-12-31 23:59:59'
147-
148-
You can also create a ``copy()`` of an existing ``Pendulum`` instance.
149-
As expected the date, time and timezone values are all copied to the new instance.
150-
151-
.. code-block:: python
152-
153-
dt = pendulum.now()
154-
print(dt.diff(dt.copy().add(years=1)).in_years())
155-
1
156-
157-
# dt was unchanged and still holds the value of pendulum.now()
158-
159141
Finally, if you find yourself inheriting a ``datetime`` instance,
160142
you can create a ``Pendulum`` instance via the ``instance()`` function.
161143

docs/_docs/interval.rst

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ It has many improvements over the base class.
1212

1313
.. code-block:: python
1414
15+
import pendulum
16+
1517
d1 = datetime(2012, 1, 1, 1, 2, 3, tzinfo=pytz.UTC)
1618
d2 = datetime(2011, 12, 31, 22, 2, 3, tzinfo=pytz.UTC)
1719
delta = d2 - d1
@@ -20,8 +22,8 @@ It has many improvements over the base class.
2022
delta.seconds
2123
75600
2224
23-
d1 = Pendulum(2012, 1, 1, 1, 2, 3)
24-
d2 = Pendulum(2011, 12, 31, 22, 2, 3)
25+
d1 = pendulum.datetime(2012, 1, 1, 1, 2, 3)
26+
d2 = pendulum.datetime(2011, 12, 31, 22, 2, 3)
2527
delta = d2 - d1
2628
delta.days
2729
0
@@ -37,7 +39,6 @@ You can create an instance in the following ways:
3739
3840
import pendulum
3941
40-
it = pendulum.Interval(days=1177, seconds=7284, microseconds=1234)
4142
it = pendulum.interval(days=1177, seconds=7284, microseconds=1234)
4243
4344
# You can use an existing timedelta instance
@@ -63,7 +64,7 @@ The ``Interval`` class brings more properties than the default ``days``, ``secon
6364
1117
6465
6566
# If you want the remaining days not included in full weeks
66-
it.remaning_days
67+
it.remaining_days
6768
1
6869
6970
# The remaining number in each unit

docs/_docs/introduction.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ For example all comparisons are done in UTC or in the timezone of the datetime b
1616
1717
import pendulum
1818
19-
dt_toronto = pendulum.create(2012, 1, 1, tz='America/Toronto')
20-
dt_vancouver = pendulum.create(2012, 1, 1, tz='America/Vancouver')
19+
dt_toronto = pendulum.datetime(2012, 1, 1, tz='America/Toronto')
20+
dt_vancouver = pendulum.datetime(2012, 1, 1, tz='America/Vancouver')
2121
2222
print(dt_vancouver.diff(dt_toronto).in_hours())
2323
3

docs/_docs/localization.rst

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ Localization occurs when using the ``format()`` method which accepts a ``locale`
55

66
.. code-block:: python
77
8-
from pendulum import Pendulum
8+
import pendulum
99
10-
dt = Pendulum(1975, 5, 21)
10+
dt = pendulum.datetime(1975, 5, 21)
1111
1212
dt.format('%A %d %B %Y', locale='de')
1313
'Mittwoch 21 Mai 1975'
@@ -22,9 +22,10 @@ Localization occurs when using the ``format()`` method which accepts a ``locale`
2222
.. code-block:: python
2323
2424
import locale
25-
from pendulum import Pendulum
2625
27-
dt = Pendulum(1975, 5, 21)
26+
import pendulum
27+
28+
dt = pendulum.datetime(1975, 5, 21)
2829
2930
locale.setlocale(locale.setlocale(locale.LC_ALL, 'de_DE.UTF-8'))
3031
dt.format('%A %d %B %Y')

0 commit comments

Comments
 (0)