Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow timezones to be created directly within arrow #969

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Rename to timezone instead of zone
  • Loading branch information
systemcatch committed Nov 6, 2021
commit 6a21daf4dd3e17d8a37e83a529b6b72f358f3167
4 changes: 2 additions & 2 deletions arrow/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from ._version import __version__
from .api import get, now, utcnow, zone
from .api import get, now, timezone, utcnow
from .arrow import Arrow
from .factory import ArrowFactory
from .formatter import (
Expand All @@ -23,7 +23,7 @@
"get",
"now",
"utcnow",
"zone",
"timezone",
"Arrow",
"ArrowFactory",
"FORMAT_ATOM",
Expand Down
8 changes: 3 additions & 5 deletions arrow/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
from time import struct_time
from typing import Any, List, Optional, Tuple, Type, Union, overload

from dateutil import tz as dateutil_tz

from arrow.arrow import TZ_EXPR, Arrow
from arrow.constants import DEFAULT_LOCALE
from arrow.factory import ArrowFactory
Expand Down Expand Up @@ -114,8 +112,8 @@ def now(tz: Optional[TZ_EXPR] = None) -> Arrow:
now.__doc__ = _factory.now.__doc__


def zone(zone_name: str) -> dateutil_tz:
return _factory.zone(zone_name)
def timezone(zone_name: str) -> dt_tzinfo:
return _factory.timezone(zone_name)


def factory(type: Type[Arrow]) -> ArrowFactory:
Expand All @@ -129,4 +127,4 @@ def factory(type: Type[Arrow]) -> ArrowFactory:
return ArrowFactory(type)


__all__ = ["get", "utcnow", "now", "factory", "zone"]
__all__ = ["get", "utcnow", "now", "factory", "timezone"]
2 changes: 1 addition & 1 deletion arrow/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ def now(self, tz: Optional[TZ_EXPR] = None) -> Arrow:
return self.type.now(tz)

@staticmethod
def zone(zone_name: str) -> dateutil_tz:
def timezone(zone_name: str) -> dt_tzinfo:
"""docstring here"""
zone = parser.TzinfoParser.parse(zone_name)

Expand Down
12 changes: 12 additions & 0 deletions tests/test_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -434,3 +434,15 @@ def test_tzinfo(self):
def test_tz_str(self):

assert_datetime_equality(self.factory.now("EST"), datetime.now(tz.gettz("EST")))


@pytest.mark.usefixtures("arrow_factory")
class TestTimezone:
def test_timezone(self):

assert self.factory.timezone("Australia/Darwin") == tz.gettz("Australia/Darwin")

def test_bad_input(self):

with pytest.raises(ParserError):
self.factory.timezone("absolute garbage#!?")