Skip to content

Commit

Permalink
Merge branch 'master' into add-python-versions-and-bump-ci-deps
Browse files Browse the repository at this point in the history
  • Loading branch information
krisfremen authored Oct 18, 2024
2 parents 4a4e9b2 + 6321d81 commit 9addcd5
Show file tree
Hide file tree
Showing 13 changed files with 62 additions and 31 deletions.
6 changes: 6 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
version: 2
updates:
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "weekly"
7 changes: 4 additions & 3 deletions arrow/arrow.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from datetime import date
from datetime import datetime as dt_datetime
from datetime import time as dt_time
from datetime import timedelta
from datetime import timedelta, timezone
from datetime import tzinfo as dt_tzinfo
from math import trunc
from time import struct_time
Expand Down Expand Up @@ -1087,7 +1087,8 @@ def format(
self, fmt: str = "YYYY-MM-DD HH:mm:ssZZ", locale: str = DEFAULT_LOCALE
) -> str:
"""Returns a string representation of the :class:`Arrow <arrow.arrow.Arrow>` object,
formatted according to the provided format string.
formatted according to the provided format string. For a list of formatting values,
see :ref:`supported-tokens`
:param fmt: the format string.
:param locale: the locale to format.
Expand Down Expand Up @@ -1142,7 +1143,7 @@ def humanize(
locale = locales.get_locale(locale)

if other is None:
utc = dt_datetime.utcnow().replace(tzinfo=dateutil_tz.tzutc())
utc = dt_datetime.now(timezone.utc).replace(tzinfo=dateutil_tz.tzutc())
dt = utc.astimezone(self._datetime.tzinfo)

elif isinstance(other, Arrow):
Expand Down
10 changes: 5 additions & 5 deletions arrow/locales.py
Original file line number Diff line number Diff line change
Expand Up @@ -654,20 +654,20 @@ class FrenchCanadianLocale(FrenchBaseLocale, Locale):
class GreekLocale(Locale):
names = ["el", "el-gr"]

past = "{0} πριν"
past = "πριν από {0}"
future = "σε {0}"
and_word = "και"

timeframes = {
"now": "τώρα",
"second": "ένα δεύτερο",
"second": "ένα δευτερόλεπτο",
"seconds": "{0} δευτερόλεπτα",
"minute": "ένα λεπτό",
"minutes": "{0} λεπτά",
"hour": "μία ώρα",
"hours": "{0} ώρες",
"day": "μία μέρα",
"days": "{0} μέρες",
"day": "μία ημέρα",
"days": "{0} ημέρες",
"week": "μία εβδομάδα",
"weeks": "{0} εβδομάδες",
"month": "ένα μήνα",
Expand Down Expand Up @@ -697,7 +697,7 @@ class GreekLocale(Locale):
"Φεβ",
"Μαρ",
"Απρ",
"Μαϊ",
"Μαΐ",
"Ιον",
"Ιολ",
"Αυγ",
Expand Down
4 changes: 4 additions & 0 deletions docs/guide.rst
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,8 @@ Move between the earlier and later moments of an ambiguous time:
Format
~~~~~~

For a list of formatting values, see :ref:`supported-tokens`

.. code-block:: python
>>> arrow.utcnow().format('YYYY-MM-DD HH:mm:ss ZZ')
Expand Down Expand Up @@ -365,6 +367,8 @@ Then get and use a factory for it:
>>> custom.days_till_xmas()
>>> 211
.. _supported-tokens:

Supported Tokens
~~~~~~~~~~~~~~~~

Expand Down
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ classifiers = [
]
dependencies = [
"python-dateutil>=2.7.0",
"types-python-dateutil>=2.8.10",
]
requires-python = ">=3.8"
description = "Better dates & times for Python"
Expand Down
1 change: 1 addition & 0 deletions requirements/requirements-tests.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ pytest-cov
pytest-mock
pytz==2021.1
simplejson==3.*
types-python-dateutil>=2.8.10
1 change: 0 additions & 1 deletion requirements/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
python-dateutil>=2.7.0
types-python-dateutil>=2.8.10
14 changes: 9 additions & 5 deletions tests/test_arrow.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import pickle
import sys
import time
from datetime import date, datetime, timedelta
from datetime import date, datetime, timedelta, timezone
from typing import List

import dateutil
Expand Down Expand Up @@ -91,7 +91,7 @@ def test_utcnow(self):
result = arrow.Arrow.utcnow()

assert_datetime_equality(
result._datetime, datetime.utcnow().replace(tzinfo=tz.tzutc())
result._datetime, datetime.now(timezone.utc).replace(tzinfo=tz.tzutc())
)

assert result.fold == 0
Expand Down Expand Up @@ -124,7 +124,7 @@ def test_utcfromtimestamp(self):

result = arrow.Arrow.utcfromtimestamp(timestamp)
assert_datetime_equality(
result._datetime, datetime.utcnow().replace(tzinfo=tz.tzutc())
result._datetime, datetime.now(timezone.utc).replace(tzinfo=tz.tzutc())
)

with pytest.raises(ValueError):
Expand Down Expand Up @@ -1055,7 +1055,11 @@ def test_imaginary(self):

def test_unsupported(self):
with pytest.raises(ValueError):
next(arrow.Arrow.range("abc", datetime.utcnow(), datetime.utcnow()))
next(
arrow.Arrow.range(
"abc", datetime.now(timezone.utc), datetime.now(timezone.utc)
)
)

def test_range_over_months_ending_on_different_days(self):
# regression test for issue #842
Expand Down Expand Up @@ -2889,7 +2893,7 @@ def test_get_datetime(self):
get_datetime = arrow.Arrow._get_datetime

arw = arrow.Arrow.utcnow()
dt = datetime.utcnow()
dt = datetime.now(timezone.utc)
timestamp = time.time()

assert get_datetime(arw) == arw.datetime
Expand Down
20 changes: 10 additions & 10 deletions tests/test_factory.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import time
from datetime import date, datetime
from datetime import date, datetime, timezone
from decimal import Decimal

import pytest
Expand All @@ -15,7 +15,7 @@
class TestGet:
def test_no_args(self):
assert_datetime_equality(
self.factory.get(), datetime.utcnow().replace(tzinfo=tz.tzutc())
self.factory.get(), datetime.now(timezone.utc).replace(tzinfo=tz.tzutc())
)

def test_timestamp_one_arg_no_arg(self):
Expand All @@ -31,7 +31,7 @@ def test_one_arg_none(self):
def test_struct_time(self):
assert_datetime_equality(
self.factory.get(time.gmtime()),
datetime.utcnow().replace(tzinfo=tz.tzutc()),
datetime.now(timezone.utc).replace(tzinfo=tz.tzutc()),
)

def test_one_arg_timestamp(self):
Expand Down Expand Up @@ -91,7 +91,7 @@ def test_one_arg_arrow(self):
assert arw == result

def test_one_arg_datetime(self):
dt = datetime.utcnow().replace(tzinfo=tz.tzutc())
dt = datetime.now(timezone.utc).replace(tzinfo=tz.tzutc())

assert self.factory.get(dt) == dt

Expand All @@ -103,7 +103,7 @@ def test_one_arg_date(self):

def test_one_arg_tzinfo(self):
self.expected = (
datetime.utcnow()
datetime.now(timezone.utc)
.replace(tzinfo=tz.tzutc())
.astimezone(tz.gettz("US/Pacific"))
)
Expand All @@ -123,7 +123,7 @@ def test_one_arg_dateparser_datetime(self):

def test_kwarg_tzinfo(self):
self.expected = (
datetime.utcnow()
datetime.now(timezone.utc)
.replace(tzinfo=tz.tzutc())
.astimezone(tz.gettz("US/Pacific"))
)
Expand All @@ -134,7 +134,7 @@ def test_kwarg_tzinfo(self):

def test_kwarg_tzinfo_string(self):
self.expected = (
datetime.utcnow()
datetime.now(timezone.utc)
.replace(tzinfo=tz.tzutc())
.astimezone(tz.gettz("US/Pacific"))
)
Expand Down Expand Up @@ -199,7 +199,7 @@ def test_one_arg_iso_calendar_tzinfo_kwarg(self):
assert_datetime_equality(result, expected)

def test_one_arg_iso_str(self):
dt = datetime.utcnow()
dt = datetime.now(timezone.utc)

assert_datetime_equality(
self.factory.get(dt.isoformat()), dt.replace(tzinfo=tz.tzutc())
Expand Down Expand Up @@ -273,7 +273,7 @@ def test_two_args_date_tz_str(self):

def test_two_args_datetime_other(self):
with pytest.raises(TypeError):
self.factory.get(datetime.utcnow(), object())
self.factory.get(datetime.now(timezone.utc), object())

def test_two_args_date_other(self):
with pytest.raises(TypeError):
Expand Down Expand Up @@ -374,7 +374,7 @@ class TestUtcNow:
def test_utcnow(self):
assert_datetime_equality(
self.factory.utcnow()._datetime,
datetime.utcnow().replace(tzinfo=tz.tzutc()),
datetime.now(timezone.utc).replace(tzinfo=tz.tzutc()),
)


Expand Down
4 changes: 2 additions & 2 deletions tests/test_formatter.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from datetime import datetime
from datetime import datetime, timezone

import pytest
import pytz
Expand Down Expand Up @@ -113,7 +113,7 @@ def test_timestamp(self):
assert self.formatter._format_token(dt, "x") == expected

def test_timezone(self):
dt = datetime.utcnow().replace(tzinfo=dateutil_tz.gettz("US/Pacific"))
dt = datetime.now(timezone.utc).replace(tzinfo=dateutil_tz.gettz("US/Pacific"))

result = self.formatter._format_token(dt, "ZZ")
assert result == "-07:00" or result == "-08:00"
Expand Down
17 changes: 17 additions & 0 deletions tests/test_locales.py
Original file line number Diff line number Diff line change
Expand Up @@ -3178,3 +3178,20 @@ def test_plurals_mk(self):
assert self.locale._format_timeframe("months", 11) == "11 oy"
assert self.locale._format_timeframe("year", 1) == "bir yil"
assert self.locale._format_timeframe("years", 12) == "12 yil"


@pytest.mark.usefixtures("lang_locale")
class TestGreekLocale:
def test_format_relative_future(self):
result = self.locale._format_relative("μία ώρα", "ώρα", -1)

assert result == "πριν από μία ώρα" # an hour ago

def test_month_abbreviation(self):
assert self.locale.month_abbreviations[5] == "Μαΐ"

def test_format_timeframe(self):
assert self.locale._format_timeframe("second", 1) == "ένα δευτερόλεπτο"
assert self.locale._format_timeframe("seconds", 3) == "3 δευτερόλεπτα"
assert self.locale._format_timeframe("day", 1) == "μία ημέρα"
assert self.locale._format_timeframe("days", 6) == "6 ημέρες"
4 changes: 2 additions & 2 deletions tests/test_parser.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import calendar
import os
import time
from datetime import datetime
from datetime import datetime, timezone

import pytest
from dateutil import tz
Expand Down Expand Up @@ -1149,7 +1149,7 @@ def test_gnu_date(self):
)

def test_isoformat(self):
dt = datetime.utcnow()
dt = datetime.now(timezone.utc)

assert self.parser.parse_iso(dt.isoformat()) == dt

Expand Down
4 changes: 2 additions & 2 deletions tests/test_util.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import time
from datetime import datetime
from datetime import datetime, timezone

import pytest

Expand Down Expand Up @@ -87,7 +87,7 @@ def test_validate_ordinal(self):
except (ValueError, TypeError) as exp:
pytest.fail(f"Exception raised when shouldn't have ({type(exp)}).")

ordinal = datetime.utcnow().toordinal()
ordinal = datetime.now(timezone.utc).toordinal()
ordinal_str = str(ordinal)
ordinal_float = float(ordinal) + 0.5

Expand Down

0 comments on commit 9addcd5

Please sign in to comment.