Skip to content

Commit

Permalink
feat($arrow): add demo for arrow
Browse files Browse the repository at this point in the history
  • Loading branch information
johnnymillergh committed Apr 19, 2023
1 parent dbc246f commit e8e2d9c
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
10 changes: 10 additions & 0 deletions python_boilerplate/demo/arrow_usage.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import arrow
from arrow import Arrow


def string_to_datetime(datetime: str) -> Arrow:
return arrow.get(datetime)


def convert_time_zone(source: Arrow, target_time_zone: str) -> Arrow:
return source.to(target_time_zone)
32 changes: 32 additions & 0 deletions tests/demo/test_arrow_usage.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import arrow
from loguru import logger

from python_boilerplate.demo.arrow_usage import convert_time_zone, string_to_datetime


def test_string_to_datetime():
datetime = string_to_datetime("2022-01-01 15:15:00")
assert datetime is not None
tzinfo = datetime.tzinfo
assert tzinfo is not None
logger.info(f"Parsed time zone: {tzinfo}")
now = arrow.now()
assert datetime < now
logger.info(f"Now: {now}, datetime: {datetime}")


def test_convert_time_zone():
now = arrow.now()
converted = convert_time_zone(now, "UTC+0")
logger.info(f"Now: {now}, converted UTC+0: {converted}")
assert converted is not None
converted = convert_time_zone(converted, "UTC+1")
tzinfo = converted.tzinfo
assert tzinfo is not None
logger.info(f"Now: {now}, converted UTC+1: {converted}")
assert converted is not None
converted = convert_time_zone(converted.shift(days=-1), "UTC+2")
logger.info(f"Now: {now}, converted UTC+2: {converted}")
assert converted is not None
assert converted < now
logger.info(f"Now: {now}, converted: {converted}")

0 comments on commit e8e2d9c

Please sign in to comment.