Skip to content

Commit

Permalink
Revert "Delete solutions/Time_Conversion.py"
Browse files Browse the repository at this point in the history
This reverts commit ee3ed85.
  • Loading branch information
safaabuzaid committed Jan 12, 2025
1 parent 25ed4d0 commit 9443014
Showing 1 changed file with 65 additions and 0 deletions.
65 changes: 65 additions & 0 deletions solutions/Time_Conversion.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
"""
A module for Converting time from Eastern Standard Time zone (EST) to Arabia
Standard Time (AST)
Created on 2025-01-07
Author: Safaa Osman
"""


def Time_Conversion(est_time: str) -> str:
"""Returns a time in Arabia Standard Time zone (AST)
Takes input time in the format HH:MM (24-hours format) and returns
the equavelent time in AST in the same format.
Parameters:
EST_Time (str): time in EST in the format 24 hour
Returns -> str: time in AST in the format 24 hour
Raises:
TypeError: if the input is not a string
AssertionError: if the hours are not between the boundary of (0-23)
AssertionError: if the minutes are not between the boundary of (0-59)
AssertionError: if the input is empty string
Examples:
>>> Time_Conversion("14:30")
'22:30'
>>> Time_Conversion("08:15")
'16:15'
>>> Time_Conversion("00:00")
'08:00'
"""
assert est_time != "", "input should be a time in HH:MM format"

assert isinstance(est_time, str), "The input must be string"

# split the input to hours and minutes in integers
hours, minutes = est_time.split(":")

# Assert hours and minutes are numbers
assert hours.isdigit(), "hours must be integers"
assert minutes.isdigit(), "minutes must be integers"

hours = int(hours)
minutes = int(minutes)

# Assert boundary
if not (0 <= hours <= 23):
raise ValueError("hours must be between 0 and 23")
if not (0 <= minutes <= 59):
raise ValueError("minutes must be between 0 and 59")

hours += 8

if hours >= 24:
hours -= 24

return f"{str(hours).zfill(2)}:{str(minutes).zfill(2)}"

0 comments on commit 9443014

Please sign in to comment.