Skip to content
Merged
Show file tree
Hide file tree
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
26 changes: 26 additions & 0 deletions time_zone_conversion/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Time Zone Conversion

This is a python script that converts a time from one time zone to another. The possible time
zones considered are Eastern, Central, Mountain, or Pacific.

---

## Steps to Run

1. Clone/Download this repository
```
git clone clone_path
```
2. Run the program using command
```
time_zone.py
```
---

## Input
The user enters the time in the usual American way, such as 3:48pm or 11:26am. The first time zone the user enters is that of the original time and the second is the desired time zone.

---

## Output
<img src="output.PNG">
Binary file added time_zone_conversion/output.PNG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
84 changes: 84 additions & 0 deletions time_zone_conversion/time_zone.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
class InvalidHours(Exception):
"""Invalid"""
pass


class InvalidMins(Exception):
"""Invalid"""
pass


# Taking user input
starting_zone = input("Enter starting zone: ")
time = input("Enter time: ")
end_zone = input("Enter desired time zone: ")

lst = time.split(":")
hours1 = int(lst[0])
mins1 = int(lst[1][:2])
ampm = lst[1][2:]

# Exception handling
try:
if hours1 >= 12:
raise InvalidHours
except InvalidHours:
print("Invalid Hours")
exit()

try:
if mins1 >= 60:
raise InvalidMins
except InvalidMins:
print("Invalid Minutes")

# Time conversion according to zone
if starting_zone == "CST":
hours1 = hours1 + 6
pass
elif starting_zone == "EST":
hours1 = hours1 - 10
pass
elif starting_zone == "MST":
hours1 = hours1 + 7
pass
elif starting_zone == "PST":
hours1 = hours1 + 8

if hours1 > 12:
hours1 = hours1 - 12
if ampm == 'am':
ampm = 'pm'
elif ampm == 'pm':
ampm = 'am'
elif hours1 < 0:
hours1 = hours1 + 12
if ampm == 'am':
ampm = 'pm'
elif ampm == 'pm':
ampm = 'am'

if end_zone == "CST":
hours1 = hours1 - 6
elif end_zone == "EST":
hours1 = hours1 + 10
elif end_zone == "MST":
hours1 = hours1 - 7
elif end_zone == "PST":
hours1 = hours1 - 8

if hours1 > 12:
hours1 = hours1 - 12
if ampm == 'am':
ampm = 'pm'
elif ampm == 'pm':
ampm = 'am'
elif hours1 < 0:
hours1 = hours1 + 12
if ampm == 'am':
ampm = 'pm'
elif ampm == 'pm':
ampm = 'am'

# Result
print('Time: ' + str(hours1) + ":" + str(mins1) + ampm)