-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
dbc246f
commit e8e2d9c
Showing
2 changed files
with
42 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}") |