Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ jobs:
with:
path: .venv
key: venv-${{ runner.os }}-${{ steps.full-python-version.outputs.version }}-${{ hashFiles('**/poetry.lock') }}
- name: Upgrade pip
run: |
source $HOME/.poetry/env
poetry run python -m pip install pip -U
- name: Install dependencies
run: |
source $HOME/.poetry/env
Expand Down Expand Up @@ -86,6 +90,10 @@ jobs:
with:
path: .venv
key: venv-${{ runner.os }}-${{ steps.full-python-version.outputs.version }}-fix-${{ hashFiles('**/poetry.lock') }}
- name: Upgrade pip
run: |
source $HOME/.poetry/env
poetry run python -m pip install pip -U
- name: Install dependencies
run: |
source $HOME/.poetry/env
Expand Down Expand Up @@ -127,6 +135,10 @@ jobs:
with:
path: .venv
key: venv-${{ runner.os }}-${{ steps.full-python-version.outputs.version }}-${{ hashFiles('**/poetry.lock') }}
- name: Upgrade pip
run: |
$env:Path += ";$env:Userprofile\.poetry\bin"
poetry run python -m pip install pip -U
- name: Install dependencies
run: |
$env:Path += ";$env:Userprofile\.poetry\bin"
Expand Down
9 changes: 9 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
Pendulum
########

**NOTE: This is a fork off of pendulum (https://github.com/sdispater/pendulum)**
The fork includes a few miscellaneous fixes. We currently publish it as jyve-pendulum.

To make a new version, do:

1. poetry version prerelease
2. poetry build
3. poetry publish -r jyve

.. image:: https://img.shields.io/pypi/v/pendulum.svg
:target: https://pypi.python.org/pypi/pendulum

Expand Down
12 changes: 11 additions & 1 deletion pendulum/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,17 @@ def now(tz=None): # type: (Optional[Union[str, _Timezone]]) -> DateTime
tz = _safe_timezone(tz)
dt = tz.convert(dt)

return instance(dt, tz)
return DateTime(
dt.year,
dt.month,
dt.day,
dt.hour,
dt.minute,
dt.second,
dt.microsecond,
tzinfo=dt.tzinfo,
fold=dt.fold if _HAS_FOLD else 0,
)


def today(tz="local"): # type: (Union[str, _Timezone]) -> DateTime
Expand Down
36 changes: 19 additions & 17 deletions pendulum/datetime.py
Original file line number Diff line number Diff line change
Expand Up @@ -1536,26 +1536,28 @@ def __reduce__(self):
def __reduce_ex__(self, protocol):
return self.__class__, self._getstate(protocol)

def _cmp(self, other, **kwargs):
# Fix for pypy which compares using this method
# which would lead to infinite recursion if we didn't override
kwargs = {"tzinfo": self.tz}
def __le__(self, other):
if isinstance(other, DateTime):
return self._cmp(other) <= 0
return super().__le__(other)

if _HAS_FOLD:
kwargs["fold"] = self.fold
def __lt__(self, other):
if isinstance(other, DateTime):
return self._cmp(other) < 0
return super().__lt__(other)

dt = datetime.datetime(
self.year,
self.month,
self.day,
self.hour,
self.minute,
self.second,
self.microsecond,
**kwargs
)
def __ge__(self, other):
# Will default to the negative of its reflection
return NotImplemented

def __gt__(self, other):
# Will default to the negative of its reflection
return NotImplemented

return 0 if dt == other else 1 if dt > other else -1
def _cmp(self, other, **kwargs):
sts = self.timestamp()
ots = other.timestamp()
return 0 if sts == ots else 1 if sts > ots else -1


DateTime.min = DateTime(1, 1, 1, 0, 0, tzinfo=UTC)
Expand Down
8 changes: 7 additions & 1 deletion pendulum/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,12 @@

import pendulum

from .date import Date
from .datetime import DateTime
from .parsing import _Interval
from .parsing import parse as base_parse
from .time import Duration
from .time import Time
from .tz import UTC


Expand All @@ -16,7 +20,9 @@
CDuration = None


def parse(text, **options): # type: (str, **typing.Any) -> str
def parse(
text, **options
): # type: (str, **typing.Any) -> typing.Union[Date, Time, DateTime, Duration]
# Use the mock now value if it exists
options["now"] = options.get("now", pendulum.get_test_now())

Expand Down
47 changes: 38 additions & 9 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 15 additions & 10 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
[build-system]
requires = ["poetry>=0.12"]
build-backend = "poetry.masonry.api"

[tool.poetry]
name = "pendulum"
version = "2.1.0"
name = "jyve-pendulum"
version = "2.1.1-alpha.1"
description = "Python datetimes made easy"
authors = ["Sébastien Eustace <sebastien@eustace.io>"]
license = "MIT"
Expand All @@ -9,12 +13,12 @@ homepage = "https://pendulum.eustace.io"
repository = "https://github.com/sdispater/pendulum"
documentation = "https://pendulum.eustace.io/docs"
keywords = ['datetime', 'date', 'time']

build = "build.py"
classifiers = [
"Private :: Do Not Upload"
]

packages = [
{include = "pendulum"},
#{include = "tests", format = "sdist"},
]
include = ["pendulum/py.typed"]

Expand All @@ -32,7 +36,7 @@ pytest = "^4.6"
pytest-cov = "^2.5"
pytz = ">=2018.3"
babel = "^2.5"
cleo = "^0.7.5"
cleo = "^0.8.1"
tox = "^3.0"
black = { version = "^19.3b0", markers = "python_version >= '3.6' and python_version < '4.0' and implementation_name != 'pypy'" }
isort = { version = "^4.3.21", markers = "python_version >= '3.6' and python_version < '4.0'" }
Expand All @@ -41,6 +45,7 @@ mkdocs = { version = "^1.0", python = "^3.5" }
pymdown-extensions = "^6.0"
pygments = "^2.2"
markdown-include = "^0.5.1"
freezegun = "^0.3.15"


[tool.isort]
Expand All @@ -62,10 +67,10 @@ known_third_party = [
"babel",
"cleo",
"dateutil",
"freezegun",
"pytzdata",
]


[build-system]
requires = ["poetry>=1.0.0b1"]
build-backend = "poetry.masonry.api"
[[tool.poetry.source]]
name = "jyve"
url = "https://pypi.fury.io/jyve"
22 changes: 22 additions & 0 deletions tests/datetime/test_comparison.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from datetime import datetime

import pendulum
import pytest
import pytz

from ..conftest import assert_datetime
Expand Down Expand Up @@ -192,6 +193,27 @@ def test_less_than_with_timezone_false():
assert not d1 < d3


@pytest.mark.parametrize(
'truth_fun',
(
lambda earlier, later: earlier < later,
lambda earlier, later: earlier <= later,
lambda earlier, later: later > earlier,
lambda earlier, later: later >= earlier,
)
)
def test_comparison_crossing_dst_transitioning_off(truth_fun):
# We only need to test turning off DST, since that's when the time
# component goes backwards.
# We start with 2019-11-03T01:30:00-0700
earlier = pendulum.datetime(2019, 11, 3, 8, 30).in_tz("US/Pacific")
# Adding 55 minutes to it, we turn off DST, but the time component is
# slightly less than before, i.e. we get 2019-11-03T01:25:00-0800
later = earlier.add(minutes=55)
# Run through all inequality-comparison functions
assert truth_fun(earlier, later)


def test_less_than_or_equal_true():
d1 = pendulum.datetime(2000, 1, 1)
d2 = pendulum.datetime(2000, 1, 2)
Expand Down
Loading