From bc3f7b1459cc19fea21d3ddada477cc5fe30efe4 Mon Sep 17 00:00:00 2001 From: Chris Brown <30196510+systemcatch@users.noreply.github.com> Date: Mon, 26 Apr 2021 22:54:20 +0100 Subject: [PATCH] Rough draft of arrow.zone() --- arrow/__init__.py | 3 ++- arrow/api.py | 8 +++++++- arrow/factory.py | 7 +++++++ 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/arrow/__init__.py b/arrow/__init__.py index bc5970970..d70706834 100644 --- a/arrow/__init__.py +++ b/arrow/__init__.py @@ -1,5 +1,5 @@ from ._version import __version__ -from .api import get, now, utcnow +from .api import get, now, utcnow, zone from .arrow import Arrow from .factory import ArrowFactory from .formatter import ( @@ -23,6 +23,7 @@ "get", "now", "utcnow", + "zone", "Arrow", "ArrowFactory", "FORMAT_ATOM", diff --git a/arrow/api.py b/arrow/api.py index d8ed24b97..058fee9b5 100644 --- a/arrow/api.py +++ b/arrow/api.py @@ -9,6 +9,8 @@ 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 @@ -112,6 +114,10 @@ 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 factory(type: Type[Arrow]) -> ArrowFactory: """Returns an :class:`.ArrowFactory` for the specified :class:`Arrow ` or derived type. @@ -123,4 +129,4 @@ def factory(type: Type[Arrow]) -> ArrowFactory: return ArrowFactory(type) -__all__ = ["get", "utcnow", "now", "factory"] +__all__ = ["get", "utcnow", "now", "factory", "zone"] diff --git a/arrow/factory.py b/arrow/factory.py index aad4af8bd..31f8fc466 100644 --- a/arrow/factory.py +++ b/arrow/factory.py @@ -346,3 +346,10 @@ def now(self, tz: Optional[TZ_EXPR] = None) -> Arrow: tz = parser.TzinfoParser.parse(tz) return self.type.now(tz) + + @staticmethod + def zone(zone_name: str) -> dateutil_tz: + """docstring here""" + zone = parser.TzinfoParser.parse(zone_name) + + return zone