Skip to content

Commit fc5623c

Browse files
authored
Merge pull request #66 from Laksh0p/patch-1
Return converted times from convert_time instead of printing
2 parents 7289848 + f567b83 commit fc5623c

1 file changed

Lines changed: 7 additions & 6 deletions

File tree

pybites_tools/worldclock.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
MINUTES_IN_HOUR = range(0, 60)
1414
MONTHS_IN_YEAR = range(1, 13)
1515
MAX_DAYS_IN_MONTH = range(1, 32)
16-
1716
load_dotenv()
1817

1918

@@ -29,14 +28,14 @@ def convert_time(
2928
day: int = None,
3029
tzone: str = None,
3130
date_offset: bool = False,
32-
) -> None:
31+
) -> list[tuple[str, str]]:
32+
results = []
3333
try:
3434
timezones = json.loads(os.environ["TIMEZONE_LIST"])
3535
except json.decoder.JSONDecodeError:
3636
raise WorldClockException(
3737
"JSON error occurred. Please check your .env file for syntax"
3838
)
39-
4039
for zone in timezones:
4140
if tz.gettz(zone) is None:
4241
raise WorldClockException(
@@ -62,8 +61,8 @@ def convert_time(
6261

6362
if date_offset:
6463
formatted_time += f" {converted_time.strftime('%d %b %Y')}"
65-
66-
print(f"{zone:25} {formatted_time}")
64+
results.append((zone, formatted_time))
65+
return results
6766

6867

6968
def main():
@@ -83,7 +82,7 @@ def main():
8382

8483
args = parser.parse_args()
8584
try:
86-
convert_time(
85+
result = convert_time(
8786
args.hour,
8887
args.minute,
8988
args.year,
@@ -95,6 +94,8 @@ def main():
9594
except WorldClockException as exc:
9695
print(exc)
9796
sys.exit(1)
97+
for zone, time in result:
98+
print(f"{zone:25} {time}")
9899

99100

100101
if __name__ == "__main__":

0 commit comments

Comments
 (0)