diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 58214074..6e220862 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -18,43 +18,62 @@ jobs: include: - os: ubuntu platform: linux - - os: windows - ls: dir - interpreter: 3.7 3.8 3.9 3.10 3.11 3.12 pypy3.8 pypy3.9 pypy3.10 - - os: windows - ls: dir - target: aarch64 - interpreter: 3.11 3.12 - - os: macos - target: aarch64 - interpreter: 3.7 3.8 3.9 3.10 3.11 3.12 pypy3.8 pypy3.9 pypy3.10 - os: ubuntu platform: linux target: aarch64 # mimalloc not supported on manylinux2014 cross-compile container extra-build-args: --no-default-features - # musllinux - - os: ubuntu - platform: linux - target: x86_64 - manylinux: musllinux_1_1 - - os: ubuntu - platform: linux - target: aarch64 - manylinux: musllinux_1_1 - os: ubuntu platform: linux target: ppc64le - interpreter: 3.7 3.8 3.9 3.10 3.11 3.12 + interpreter: 3.7 3.8 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 + interpreter: 3.7 3.8 3.9 3.10 3.11 3.12 3.13 # mimalloc not supported on manylinux2014 cross-compile container extra-build-args: --no-default-features + # musllinux + - os: ubuntu + platform: linux + target: x86_64 + manylinux: musllinux_1_1 + - os: ubuntu + platform: linux + target: aarch64 + manylinux: musllinux_1_1 + + # - os: windows + # ls: dir + # interpreter: 3.7 3.8 3.9 3.10 3.11 3.12 3.13 pypy3.8 pypy3.9 pypy3.10 + # - os: windows + # ls: dir + # target: aarch64 + # interpreter: 3.11 3.12 + + - os: windows + target: x86_64 + interpreter: pypy3.9 pypy3.10 + - os: windows + target: i686 + python-architecture: x86 + interpreter: 3.8 3.9 3.10 3.11 3.12 3.13 + - os: windows + target: aarch64 + interpreter: 3.11 3.12 3.13 + + + - os: macos + 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 + + + runs-on: ${{ matrix.os }}-latest steps: - uses: actions/checkout@v4 @@ -71,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 pypy3.7 pypy3.8 pypy3.9 pypy3.10' }} ${{ matrix.extra-build-args }} + 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 }} rust-toolchain: stable docker-options: -e CI @@ -130,16 +149,16 @@ jobs: [[ "${GITHUB_REF#refs/tags/}" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]] \ || echo ::set-output name=prerelease::true - - name: Create Release - uses: ncipollo/release-action@v1 - with: - artifacts: "dist/*" - token: ${{ secrets.GITHUB_TOKEN }} - draft: false - prerelease: steps.check-version.outputs.prerelease == 'true' - - - name: Publish to PyPI - env: - POETRY_PYPI_TOKEN_PYPI: ${{ secrets.PYPI_TOKEN }} - run: | - poetry publish + # - name: Create Release + # uses: ncipollo/release-action@v1 + # with: + # artifacts: "dist/*" + # token: ${{ secrets.GITHUB_TOKEN }} + # draft: false + # prerelease: steps.check-version.outputs.prerelease == 'true' + + # - name: Publish to PyPI + # env: + # POETRY_PYPI_TOKEN_PYPI: ${{ secrets.PYPI_TOKEN }} + # run: | + # poetry publish \ No newline at end of file diff --git a/src/pendulum/formatting/difference_formatter.py b/src/pendulum/formatting/difference_formatter.py index 588c0727..bfe5dee4 100644 --- a/src/pendulum/formatting/difference_formatter.py +++ b/src/pendulum/formatting/difference_formatter.py @@ -32,34 +32,56 @@ def format( :param absolute: Whether it's an absolute difference or not :param locale: The locale to use """ + DAYS_THRESHOLD_FOR_HALF_WEEK = 3 + DAYS_THRESHOLD_FOR_HALF_MONTH = 15 + MONTHS_THRESHOLD_FOR_HALF_YEAR = 6 + + HOURS_IN_NEARLY_A_DAY = 22 + DAYS_IN_NEARLY_A_MONTH = 27 + MONTHS_IN_NEARLY_A_YEAR = 11 + + DAYS_OF_WEEK = 7 + SECONDS_OF_MINUTE = 60 + FEW_SECONDS_MAX = 10 + + KEY_FUTURE = ".future" + KEY_PAST = ".past" + KEY_AFTER = ".after" + KEY_BEFORE = ".before" + locale = self._locale if locale is None else Locale.load(locale) if diff.years > 0: unit = "year" count = diff.years - if diff.months > 6: + if diff.months > MONTHS_THRESHOLD_FOR_HALF_YEAR: count += 1 - elif diff.months == 11 and (diff.weeks * 7 + diff.remaining_days) > 15: + elif (diff.months == MONTHS_IN_NEARLY_A_YEAR) and ( + (diff.weeks * DAYS_OF_WEEK + diff.remaining_days) + > DAYS_THRESHOLD_FOR_HALF_MONTH + ): unit = "year" count = 1 elif diff.months > 0: unit = "month" count = diff.months - if (diff.weeks * 7 + diff.remaining_days) >= 27: + if ( + diff.weeks * DAYS_OF_WEEK + diff.remaining_days + ) >= DAYS_IN_NEARLY_A_MONTH: count += 1 elif diff.weeks > 0: unit = "week" count = diff.weeks - if diff.remaining_days > 3: + if diff.remaining_days > DAYS_THRESHOLD_FOR_HALF_WEEK: count += 1 elif diff.remaining_days > 0: unit = "day" count = diff.remaining_days - if diff.hours >= 22: + if diff.hours >= HOURS_IN_NEARLY_A_DAY: count += 1 elif diff.hours > 0: unit = "hour" @@ -67,7 +89,7 @@ def format( elif diff.minutes > 0: unit = "minute" count = diff.minutes - elif 10 < diff.remaining_seconds <= 59: + elif FEW_SECONDS_MAX < diff.remaining_seconds < SECONDS_OF_MINUTE: unit = "second" count = diff.remaining_seconds else: @@ -86,9 +108,9 @@ def format( key += ".ago" else: if is_future: - key += ".after" + key += KEY_AFTER else: - key += ".before" + key += KEY_BEFORE return t.cast(str, locale.get(key).format(time)) else: @@ -109,9 +131,9 @@ def format( key = f"translations.relative.{unit}" if is_future: - key += ".future" + key += KEY_FUTURE else: - key += ".past" + key += KEY_PAST else: # Absolute comparison # So we have to use the custom locale data @@ -119,9 +141,9 @@ def format( # Checking for special pluralization rules key = "custom.units_relative" if is_future: - key += f".{unit}.future" + key += f".{unit}{KEY_FUTURE}" else: - key += f".{unit}.past" + key += f".{unit}{KEY_PAST}" trans = locale.get(key) if not trans: @@ -133,10 +155,9 @@ def format( key = "custom" if is_future: - key += ".after" + key += KEY_AFTER else: - key += ".before" - + key += KEY_BEFORE return t.cast(str, locale.get(key).format(time)) key += f".{locale.plural(count)}"