Skip to content

Commit 6089b33

Browse files
committed
Merge branch 'develop'
2 parents 8978f17 + abe9efe commit 6089b33

29 files changed

+382
-562
lines changed

.travis.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ matrix:
2222
env: PENDULUM_EXTENSIONS=1
2323
- python: 3.5
2424
env: PENDULUM_EXTENSIONS=0
25-
- python: 3.6-dev
25+
- python: 3.6
2626
env: PENDULUM_EXTENSIONS=1
27-
- python: 3.6-dev
27+
- python: 3.6
2828
env: PENDULUM_EXTENSIONS=0
2929
- python: pypy
3030

@@ -40,7 +40,7 @@ install:
4040
else
4141
rm -rf "$PYENV_ROOT" && git clone --depth 1 https://github.com/yyuu/pyenv.git "$PYENV_ROOT"
4242
fi
43-
export PYPY_VERSION="5.4.1"
43+
export PYPY_VERSION="5.6.0"
4444
"$PYENV_ROOT/bin/pyenv" install --skip-existing "pypy-$PYPY_VERSION"
4545
virtualenv --python="$PYENV_ROOT/versions/pypy-$PYPY_VERSION/bin/python" "$HOME/virtualenvs/pypy-$PYPY_VERSION"
4646
source "$HOME/virtualenvs/pypy-$PYPY_VERSION/bin/activate"

CHANGELOG.md

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

3+
4+
## [Unreleased]
5+
6+
### Changed
7+
8+
- Using `PRE_TRANSITION` rule no longer produces a time in a DST gap.
9+
- Improved performances when adding time to a `Pendulum` instance.
10+
- Improved parsing of ISO 8601 strings.
11+
- Removed deprecated methods
12+
13+
314
## [0.8.0] - 2016-12-23
415

516
### Added
@@ -291,6 +302,7 @@ This version causes major breaking API changes to simplify it and making it more
291302
Initial release
292303

293304

305+
[Unreleased]: https://github.com/sdispater/pendulum/compare/0.8.0...develop
294306
[0.8.0]: https://github.com/sdispater/pendulum/releases/tag/0.8.0
295307
[0.7.0]: https://github.com/sdispater/pendulum/releases/tag/0.7.0
296308
[0.6.6]: https://github.com/sdispater/pendulum/releases/tag/0.6.6

build-wheels.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/bin/bash
2-
PYTHON_VERSIONS="cp27-cp27m cp35-cp35m"
2+
PYTHON_VERSIONS="cp27-cp27m cp35-cp35m cp36-cp36m"
33

44
echo "Compile wheels"
55
for PYTHON in ${PYTHON_VERSIONS}; do

docs/_docs/instantiation.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ Date
180180
+-----------------------------------+-------------------------------------------+
181181
|20120503 |2012-05-03T00:00:00+00:00 |
182182
+-----------------------------------+-------------------------------------------+
183-
|2012-05 |2016-10-01T14:00:00+00:00 |
183+
|2012-05 |2012-05-01T00:00:00+00:00 |
184184
+-----------------------------------+-------------------------------------------+
185185

186186
Ordinal day

docs/_docs/interval.rst

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -86,32 +86,6 @@ The ``Interval`` class brings more properties than the default ``days``, ``secon
8686
it.microseconds
8787
1234
8888
89-
.. note::
90-
91-
You might notice that the value of the ``seconds`` property is different that
92-
the one you would obtain from the standard ``timedelta`` class.
93-
94-
.. code-block:: python
95-
96-
from datetime import timedelta
97-
98-
it = timedelta(days=1177, seconds=7284, microseconds=1234)
99-
100-
it.seconds
101-
7284
102-
103-
The reason for that is the fact that ``pendulum`` provides the ``minutes`` and ``hours``
104-
units, so ``seconds`` is just the remaining seconds after the computation of hours and minutes:
105-
106-
.. code-block:: python
107-
108-
import pendulum
109-
110-
it = pendulum.interval(days=1177, seconds=7284, microseconds=1234)
111-
112-
it.hours * 3600 + it.minutes * 60 + it.seconds
113-
7284
114-
11589
If you want to get the total duration of the interval in each supported unit
11690
you can use the appropriate methods.
11791

docs/_docs/timezones.rst

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ given timezone to properly handle any transition that might have occurred.
4343
pendulum.set_transition_rule(pendulum.PRE_TRANSITION)
4444
4545
pendulum.create(2013, 3, 31, 2, 30, 0, 0, 'Europe/Paris')
46-
'2013-03-31T02:30:00+01:00'
46+
'2013-03-31T01:30:00+01:00'
4747
pendulum.create(2013, 10, 27, 2, 30, 0, 0, 'Europe/Paris')
4848
'2013-10-27T02:30:00+02:00'
4949
@@ -75,7 +75,7 @@ given timezone to properly handle any transition that might have occurred.
7575
7676
dt = Pendulum(2013, 3, 31, 2, 30, 0, 0, 'Europe/Paris', fold=0)
7777
dt.isoformat()
78-
'2013-03-31T02:30:00+01:00'
78+
'2013-03-31T01:30:00+01:00'
7979
8080
dt = Pendulum(2013, 3, 31, 2, 30, 0, 0, 'Europe/Paris', fold=1)
8181
dt.isoformat()
@@ -94,7 +94,7 @@ Shifting time to transition
9494

9595
So, what happens when you add time to a ``Pendulum`` instance and stumble upon
9696
a transition time?
97-
Well, ``Pendulum``, provided with the context of the previous instance, will
97+
Well ``Pendulum``, provided with the context of the previous instance, will
9898
adopt the proper behavior and apply the transition accordingly.
9999

100100
.. code-block:: python
@@ -161,7 +161,7 @@ when adding and subtracting time around transition times.
161161
# By default, fold is set to 0
162162
dt = paris.convert(dt)
163163
dt.isoformat()
164-
'2013-03-31T02:30:00+01:00'
164+
'2013-03-31T01:30:00+01:00'
165165
166166
dt = datetime(2013, 3, 31, 2, 30, fold=1)
167167
dt = paris.convert(dt)
@@ -229,7 +229,7 @@ when adding and subtracting time around transition times.
229229
dt = datetime(2013, 3, 31, 2, 30)
230230
dt = tz.convert(dt, dst_rule=tz.PRE_TRANSITION)
231231
dt.isoformat()
232-
'2013-03-31T02:30:00+01:00'
232+
'2013-03-31T01:30:00+01:00'
233233
tz.convert(dt, dst_rule=tz.TRANSITION_ERROR)
234234
# NonExistingTime: The datetime 2013-03-31 02:30:00 does not exist.
235235

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/constants.py

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -53,37 +53,37 @@
5353

5454
# The number of seconds in an aligned 100-year chunk, for those that
5555
# do not begin with a leap year and those that do respectively.
56-
SECS_PER_100_YEARS = [
56+
SECS_PER_100_YEARS = (
5757
(76 * DAYS_PER_N_YEAR + 24 * DAYS_PER_L_YEAR) * SECS_PER_DAY,
58-
(75 * DAYS_PER_N_YEAR + 25 * DAYS_PER_L_YEAR) * SECS_PER_DAY,
59-
]
58+
(75 * DAYS_PER_N_YEAR + 25 * DAYS_PER_L_YEAR) * SECS_PER_DAY
59+
)
6060

6161
# The number of seconds in an aligned 4-year chunk, for those that
6262
# do not begin with a leap year and those that do respectively.
63-
SECS_PER_4_YEARS = [
63+
SECS_PER_4_YEARS = (
6464
(4 * DAYS_PER_N_YEAR + 0 * DAYS_PER_L_YEAR) * SECS_PER_DAY,
65-
(3 * DAYS_PER_N_YEAR + 1 * DAYS_PER_L_YEAR) * SECS_PER_DAY,
66-
]
65+
(3 * DAYS_PER_N_YEAR + 1 * DAYS_PER_L_YEAR) * SECS_PER_DAY
66+
)
6767

6868
# The number of seconds in non-leap and leap years respectively.
69-
SECS_PER_YEAR = [
69+
SECS_PER_YEAR = (
7070
DAYS_PER_N_YEAR * SECS_PER_DAY,
71-
DAYS_PER_L_YEAR * SECS_PER_DAY,
72-
]
71+
DAYS_PER_L_YEAR * SECS_PER_DAY
72+
)
7373

7474
# The month lengths in non-leap and leap years respectively.
75-
DAYS_PER_MONTHS = [
76-
[-1, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31],
77-
[-1, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
78-
]
75+
DAYS_PER_MONTHS = (
76+
(-1, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31),
77+
(-1, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31)
78+
)
7979

8080
# The day offsets of the beginning of each (1-based) month in non-leap
8181
# and leap years respectively.
8282
# For example, in a leap year there are 335 days before December.
83-
MONTHS_OFFSETS = [
84-
[-1, 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365],
85-
[-1, 0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335, 366]
86-
]
83+
MONTHS_OFFSETS = (
84+
(-1, 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365),
85+
(-1, 0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335, 366)
86+
)
8787

8888
TM_SUNDAY = 0
8989
TM_MONDAY = 1

pendulum/formatting/__init__.py

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

3+
from .formatter import Formatter
34
from .classic_formatter import ClassicFormatter
45
from .alternative_formatter import AlternativeFormatter
56

@@ -8,3 +9,27 @@
89
'classic': ClassicFormatter(),
910
'alternative': AlternativeFormatter(),
1011
}
12+
13+
14+
def register_formatter(name, formatter):
15+
"""
16+
Register a new formatter.
17+
18+
:param name: The name of the formatter.
19+
:type name: str
20+
21+
:param formatter: The formatter instance
22+
:type formatter: Formatter
23+
24+
:rtype: None
25+
"""
26+
if name in FORMATTERS:
27+
raise ValueError('Formatter [{}] already exists'.format(name))
28+
29+
if not isinstance(formatter, Formatter):
30+
raise ValueError(
31+
'The formatter instance '
32+
'must be an instance of Formatter'
33+
)
34+
35+
FORMATTERS[name] = formatter

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

0 commit comments

Comments
 (0)