Skip to content

Instantly share code, notes, and snippets.

@pcakhilnadh
Created January 8, 2020 12:14
Show Gist options
  • Save pcakhilnadh/40c51d8fad2ce3b61ba9e3c70d5c347a to your computer and use it in GitHub Desktop.
Save pcakhilnadh/40c51d8fad2ce3b61ba9e3c70d5c347a to your computer and use it in GitHub Desktop.
To find the total working hours you have worked for the day and week. This will also tell you how long you will have to work in a day before you can leave your office. Ofcourse, we all need some time to spend with our family and friends.
from datetime import datetime
import sys
def HHandMM_splitter(time):
timeHH,timeMM= time.split(':')
timeMM=timeMM[:-2]
if time[-2:]=='PM':
timeHH=str(12+int(timeHH))
return timeHH,timeMM
def timeDiff(timeObj1,timeObj2):
return timeObj2-timeObj1
def timeAdd(timeObj1,timeObj2):
return timeObj1+timeObj2
def timeObjMaker(timeHH,timeMM):
FMT = '%H:%M:%S'
time=timeHH+':'+timeMM+":00"
return datetime.strptime(time, FMT)
def remainingWHDay():
dailyLog= list(input("\n Enter the Log times : ").split())
totalWorkTime=timeObjMaker('00','00')
for i in range(0,len(dailyLog),2):
HH,MM = HHandMM_splitter(dailyLog[i])
timeIN=timeObjMaker(HH,MM)
HH,MM = HHandMM_splitter(dailyLog[i+1])
timeOUT=timeObjMaker(HH,MM)
totalWorkTime=totalWorkTime+(timeDiff(timeIN,timeOUT))
print("TotalWork Time of The Day : ",str(totalWorkTime).split()[1])
print("\n \n \n")
def remainingWHWeek():
WeeklyLog= list(map(float,(input("\n Enter the Log times : ").split())))
print(" Remaining Time Needed", 40-sum(WeeklyLog))
print("\n \n \n")
def main():
while True:
print("1: Remaining Working Hours For the Day \n2. Remaining Time for the Week\n3. Exit")
option = int(input("Enter Your Option : "))
if option == 1:
remainingWHDay()
elif option == 2:
remainingWHWeek()
else:
sys.exit()
if __name__== "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment