Skip to content

Commit

Permalink
Merge branch 'python-pendulum-master'
Browse files Browse the repository at this point in the history
  • Loading branch information
rudolfix committed Dec 28, 2024
2 parents aa0472f + 2242207 commit 24f40f6
Show file tree
Hide file tree
Showing 30 changed files with 1,052 additions and 764 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ jobs:
- os: ubuntu
platform: linux
target: ppc64le
interpreter: 3.7 3.8 3.9 3.10 3.11 3.12 3.13
interpreter: 3.9 3.10 3.11 3.12 3.13
# mimalloc not supported on manylinux2014 cross-compile container
extra-build-args: --no-default-features
- os: ubuntu
platform: linux
target: s390x
interpreter: 3.7 3.8 3.9 3.10 3.11 3.12 3.13
interpreter: 3.9 3.10 3.11 3.12 3.13
# mimalloc not supported on manylinux2014 cross-compile container
extra-build-args: --no-default-features

Expand Down Expand Up @@ -60,7 +60,7 @@ jobs:
- os: windows
target: i686
python-architecture: x86
interpreter: 3.8 3.9 3.10 3.11 3.12 3.13
interpreter: 3.9 3.10 3.11 3.12 3.13
- os: windows
target: aarch64
interpreter: 3.11 3.12 3.13
Expand All @@ -70,7 +70,7 @@ jobs:
target: x86_64
- os: macos
target: aarch64
interpreter: 3.7 3.8 3.9 3.10 3.11 3.12 3.13 pypy3.8 pypy3.9 pypy3.10
interpreter: 3.9 3.10 3.11 3.12 3.13 pypy3.8 pypy3.9 pypy3.10



Expand All @@ -90,7 +90,7 @@ jobs:
target: ${{ matrix.target }}
manylinux: ${{ matrix.manylinux || 'auto' }}
container: ${{ matrix.container }}
args: --release --out dist --interpreter ${{ matrix.interpreter || '3.7 3.8 3.9 3.10 3.11 3.12 3.13 pypy3.7 pypy3.8 pypy3.9 pypy3.10' }} ${{ matrix.extra-build-args }}
args: --release --out dist --interpreter ${{ matrix.interpreter || '3.9 3.10 3.11 3.12 3.13 pypy3.9 pypy3.10' }} ${{ matrix.extra-build-args }}
rust-toolchain: stable
docker-options: -e CI

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:
strategy:
matrix:
os: [Ubuntu, MacOS, Windows]
python-version: [3.8, 3.9, "3.10", "3.11", "3.12", "3.13"]
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"]
defaults:
run:
shell: bash
Expand Down
10 changes: 9 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,12 @@ format-rust:
cd rust && cargo clippy --tests --fix --allow-dirty -- -D warnings

dev:
poetry install
poetry install --only main --only test --only typing --only build
poetry run maturin develop

lint:
poetry run mypy

test:
PENDULUM_EXTENSIONS=0 poetry run pytest -q tests
poetry run pytest -q tests
3 changes: 1 addition & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,9 @@ Pendulum
:alt: Pendulum Build status
:target: https://github.com/sdispater/pendulum/actions


Python datetimes made easy.

Supports Python **3.8 and newer**.
Supports Python **3.9 and newer**.


.. code-block:: python
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/modifiers.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,6 @@ True
'2014-01-15 12:00:00'

# others that are defined that are similar
# and tha accept month, quarter and year units
# and that accept month, quarter and year units
# first_of(), last_of(), nth_of()
```
1,132 changes: 559 additions & 573 deletions poetry.lock

Large diffs are not rendered by default.

14 changes: 5 additions & 9 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@ name = "pendulum"
version = "3.0.1"
description = "Python datetimes made easy"
readme = "README.rst"
requires-python = ">=3.8"
requires-python = ">=3.9"
license = { text = "MIT License" }
authors = [{ name = "Sébastien Eustace", email = "[email protected]" }]
keywords = ['datetime', 'date', 'time']

classifiers = [
"License :: OSI Approved :: MIT License",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
Expand All @@ -22,8 +21,6 @@ classifiers = [
dependencies = [
"python-dateutil>=2.6",
"tzdata>=2020.1",
'backports.zoneinfo>=0.2.1; python_version < "3.9"',
'importlib-resources>=5.9.0; python_version < "3.9"',
"cffi>=1.17",
]

Expand All @@ -47,17 +44,15 @@ keywords = ['datetime', 'date', 'time']


[tool.poetry.dependencies]
python = ">=3.8"
python = ">=3.9"
cffi = ">=1.17"
python-dateutil = ">=2.6"
"backports.zoneinfo" = { version = ">=0.2.1", python = "<3.9" }
tzdata = ">=2020.1"
importlib-resources = { version = ">=5.9.0", python = "<3.9" }

[tool.poetry.group.test.dependencies]
pytest = "^7.1.2"
pytz = ">=2022.1"
time-machine = ">=2.6.0"
time-machine = ">=2.16.0"
pytest-benchmark = "^4.0.0"

[tool.poetry.group.doc.dependencies]
Expand Down Expand Up @@ -85,6 +80,7 @@ ruff = "^0.7.3"

[tool.poetry.group.build.dependencies]
maturin = ">=1.0,<2.0"
patchelf = ">=17"

[tool.poetry.extras]
test = ["time-machine"]
Expand All @@ -98,7 +94,7 @@ fix = true
unfixable = [
"ERA", # do not autoremove commented out code
]
target-version = "py38"
target-version = "py39"
line-length = 88
extend-select = [
"B", # flake8-bugbear
Expand Down
38 changes: 19 additions & 19 deletions rust/src/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,57 +49,57 @@ pub fn local_time(
microsecond: usize,
) -> (usize, usize, usize, usize, usize, usize, usize) {
let mut year: usize = EPOCH_YEAR as usize;
let mut seconds: isize = unix_time.floor() as isize;
let mut seconds: i64 = unix_time.floor() as i64;

// Shift to a base year that is 400-year aligned.
if seconds >= 0 {
seconds -= (10957 * SECS_PER_DAY as usize) as isize;
seconds -= 10957 * SECS_PER_DAY as i64;
year += 30; // == 2000
} else {
seconds += ((146_097 - 10957) * SECS_PER_DAY as usize) as isize;
seconds += (146_097 - 10957) * SECS_PER_DAY as i64;
year -= 370; // == 1600
}

seconds += utc_offset;
seconds += utc_offset as i64;

// Handle years in chunks of 400/100/4/1
year += 400 * (seconds / SECS_PER_400_YEARS as isize) as usize;
seconds %= SECS_PER_400_YEARS as isize;
year += 400 * (seconds / SECS_PER_400_YEARS as i64) as usize;
seconds %= SECS_PER_400_YEARS as i64;
if seconds < 0 {
seconds += SECS_PER_400_YEARS as isize;
seconds += SECS_PER_400_YEARS as i64;
year -= 400;
}

let mut leap_year = 1; // 4-century aligned
let mut sec_per_100years = SECS_PER_100_YEARS[leap_year] as isize;
let mut sec_per_100years = SECS_PER_100_YEARS[leap_year].try_into().unwrap();

while seconds >= sec_per_100years {
seconds -= sec_per_100years;
year += 100;
leap_year = 0; // 1-century, non 4-century aligned
sec_per_100years = SECS_PER_100_YEARS[leap_year] as isize;
sec_per_100years = SECS_PER_100_YEARS[leap_year].try_into().unwrap();
}

let mut sec_per_4years = SECS_PER_4_YEARS[leap_year] as isize;
let mut sec_per_4years = SECS_PER_4_YEARS[leap_year].into();
while seconds >= sec_per_4years {
seconds -= sec_per_4years;
year += 4;
leap_year = 1; // 4-year, non century aligned
sec_per_4years = SECS_PER_4_YEARS[leap_year] as isize;
sec_per_4years = SECS_PER_4_YEARS[leap_year].into();
}

let mut sec_per_year = SECS_PER_YEAR[leap_year] as isize;
let mut sec_per_year = SECS_PER_YEAR[leap_year].into();
while seconds >= sec_per_year {
seconds -= sec_per_year;
year += 1;
leap_year = 0; // non 4-year aligned
sec_per_year = SECS_PER_YEAR[leap_year] as isize;
sec_per_year = SECS_PER_YEAR[leap_year].into();
}

// Handle months and days
let mut month = TM_DECEMBER + 1;
let mut day: usize = (seconds / (SECS_PER_DAY as isize) + 1) as usize;
seconds %= SECS_PER_DAY as isize;
let mut day: usize = (seconds / (SECS_PER_DAY as i64) + 1) as usize;
seconds %= SECS_PER_DAY as i64;

let mut month_offset: usize;
while month != (TM_JANUARY + 1) {
Expand All @@ -113,10 +113,10 @@ pub fn local_time(
}

// Handle hours, minutes and seconds
let hour: usize = (seconds / SECS_PER_HOUR as isize) as usize;
seconds %= SECS_PER_HOUR as isize;
let minute: usize = (seconds / SECS_PER_MIN as isize) as usize;
let second: usize = (seconds % SECS_PER_MIN as isize) as usize;
let hour: usize = (seconds / SECS_PER_HOUR as i64) as usize;
seconds %= SECS_PER_HOUR as i64;
let minute: usize = (seconds / SECS_PER_MIN as i64) as usize;
let second: usize = (seconds % SECS_PER_MIN as i64) as usize;

(year, month, day, hour, minute, second, microsecond)
}
4 changes: 3 additions & 1 deletion src/pendulum/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,9 @@ def duration(
)


def interval(start: DateTime, end: DateTime, absolute: bool = False) -> Interval:
def interval(
start: DateTime, end: DateTime, absolute: bool = False
) -> Interval[DateTime]:
"""
Create an Interval instance.
"""
Expand Down
2 changes: 1 addition & 1 deletion src/pendulum/_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import datetime
import math
import zoneinfo

from typing import NamedTuple
from typing import cast
Expand All @@ -22,7 +23,6 @@
from pendulum.constants import TM_DECEMBER
from pendulum.constants import TM_JANUARY
from pendulum.tz.timezone import Timezone
from pendulum.utils._compat import zoneinfo


class PreciseDiff(NamedTuple):
Expand Down
7 changes: 4 additions & 3 deletions src/pendulum/date.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,9 +263,10 @@ def __sub__(self, __delta: timedelta) -> Self: ...
def __sub__(self, __dt: datetime) -> NoReturn: ...

@overload
def __sub__(self, __dt: Self) -> Interval: ...
def __sub__(self, __dt: Self) -> Interval[Date]:
...

def __sub__(self, other: timedelta | date) -> Self | Interval:
def __sub__(self, other: timedelta | date) -> Self | Interval[Date]:
if isinstance(other, timedelta):
return self._subtract_timedelta(other)

Expand All @@ -278,7 +279,7 @@ def __sub__(self, other: timedelta | date) -> Self | Interval:

# DIFFERENCES

def diff(self, dt: date | None = None, abs: bool = True) -> Interval:
def diff(self, dt: date | None = None, abs: bool = True) -> Interval[Date]:
"""
Returns the difference between two Date objects as an Interval.
Expand Down
11 changes: 7 additions & 4 deletions src/pendulum/datetime.py
Original file line number Diff line number Diff line change
Expand Up @@ -702,7 +702,7 @@ def _subtract_timedelta(self, delta: datetime.timedelta) -> Self:

def diff( # type: ignore[override]
self, dt: datetime.datetime | None = None, abs: bool = True
) -> Interval:
) -> Interval[datetime.datetime]:
"""
Returns the difference between two DateTime objects represented as an Interval.
"""
Expand Down Expand Up @@ -1187,9 +1187,12 @@ def average( # type: ignore[override]
def __sub__(self, other: datetime.timedelta) -> Self: ...

@overload
def __sub__(self, other: DateTime) -> Interval: ...
def __sub__(self, other: DateTime) -> Interval[datetime.datetime]:
...

def __sub__(self, other: datetime.datetime | datetime.timedelta) -> Self | Interval:
def __sub__(
self, other: datetime.datetime | datetime.timedelta
) -> Self | Interval[datetime.datetime]:
if isinstance(other, datetime.timedelta):
return self._subtract_timedelta(other)

Expand All @@ -1212,7 +1215,7 @@ def __sub__(self, other: datetime.datetime | datetime.timedelta) -> Self | Inter

return other.diff(self, False)

def __rsub__(self, other: datetime.datetime) -> Interval:
def __rsub__(self, other: datetime.datetime) -> Interval[datetime.datetime]:
if not isinstance(other, datetime.datetime):
return NotImplemented

Expand Down
4 changes: 2 additions & 2 deletions src/pendulum/formatting/formatter.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
import datetime
import re

from collections.abc import Sequence
from re import Match
from typing import TYPE_CHECKING
from typing import Any
from typing import Callable
from typing import ClassVar
from typing import Match
from typing import Sequence
from typing import cast

import pendulum
Expand Down
Loading

0 comments on commit 24f40f6

Please sign in to comment.