Skip to content
Open
Changes from all commits
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
13 changes: 7 additions & 6 deletions pybites_tools/worldclock.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
MINUTES_IN_HOUR = range(0, 60)
MONTHS_IN_YEAR = range(1, 13)
MAX_DAYS_IN_MONTH = range(1, 32)

load_dotenv()


Expand All @@ -29,14 +28,14 @@ def convert_time(
day: int = None,
tzone: str = None,
date_offset: bool = False,
) -> None:
) -> list[tuple[str, str]]:
results = []
try:
timezones = json.loads(os.environ["TIMEZONE_LIST"])
except json.decoder.JSONDecodeError:
raise WorldClockException(
"JSON error occurred. Please check your .env file for syntax"
)

for zone in timezones:
if tz.gettz(zone) is None:
raise WorldClockException(
Expand All @@ -62,8 +61,8 @@ def convert_time(

if date_offset:
formatted_time += f" {converted_time.strftime('%d %b %Y')}"

print(f"{zone:25} {formatted_time}")
results.append((zone, formatted_time))
return results


def main():
Expand All @@ -83,7 +82,7 @@ def main():

args = parser.parse_args()
try:
convert_time(
result = convert_time(
args.hour,
args.minute,
args.year,
Expand All @@ -95,6 +94,8 @@ def main():
except WorldClockException as exc:
print(exc)
sys.exit(1)
for zone, time in result:
print(f"{zone:25} {time}")


if __name__ == "__main__":
Expand Down