Skip to content

Instantly share code, notes, and snippets.

@seaukara
Created December 7, 2016 18:06
Show Gist options
  • Save seaukara/c45758e3e2861b46caa6b79a19413715 to your computer and use it in GitHub Desktop.
Save seaukara/c45758e3e2861b46caa6b79a19413715 to your computer and use it in GitHub Desktop.
from datetime import datetime, date, time, timedelta
timein = (raw_input("Time in: "))
if ":" in timein:
hour = int(timein[0])
minutes = int(timein[-2:])
start = timedelta(hours = hour, minutes = minutes)
else:
start = timedelta(hours=(int(timein)))
leavetime = raw_input("Time you are leaving: ")
if leavetime <> "":
print('{0}{1}{2}'.format('If you leave work at ', leavetime, 'pm'))
if ":" in leavetime:
hour = int(leavetime[0])
print(hour)
minutes = int(leavetime[-2:])
end = timedelta(hours = hour, minutes = minutes)
print(end)
else:
end = timedelta(hours=(int(leavetime)))
start = datetime.strptime(str(start) + "am", "%I:%M:%S%p")
end = datetime.strptime(str(end) + "pm", "%I:%M:%S%p")
Lunch = (raw_input("Minutes taken for lunch:"))
if Lunch <> "":
Lunch = timedelta(minutes =int(Lunch))
Totalhrs = (end - start) - Lunch
else:
Totalhrs = (end - start)
print(Totalhrs)
Totalhrs = datetime.strptime(str(Totalhrs), "%H:%M:%S")
Totalhrs = Totalhrs.strftime("%H:%M")
Totalhrs = float(Totalhrs[:2])+(float(Totalhrs[-2:])/60)
print('{0}{1}{2}'.format('You worked ', Totalhrs, 'hrs today'))
else:
desiredhrs = str(raw_input("Desired hours of work: "))
print('{0}{1}'.format(desiredhrs, 'hrs worked'))
if "." in desiredhrs:
hour = int(desiredhrs.rsplit('.', 1)[0])
minutes = str((float("0"+(desiredhrs[-2:])))*60)
desiredhrs = timedelta(hours = hour, minutes = int(minutes.rsplit('.', -1)[0]))
elif ":" in desiredhrs:
hour = int(desiredhrs[0])
minutes = int(desiredhrs[-2:])
desiredhrs = timedelta(hours = hour, minutes = minutes)
else:
desiredhrs = timedelta(hours=(int(desiredhrs)))
start = datetime.strptime(str(start) + "am", "%I:%M:%S%p")
Lunch = (raw_input("Minutes taken for lunch: "))
if Lunch <> "":
Lunch = timedelta(minutes =int(Lunch))
timeout = (start + desiredhrs) + Lunch
else:
timeout = (start + desiredhrs)
timeout = datetime.strptime(str(timeout), "%Y-%m-%d %H:%M:%S")
timeout = timeout.strftime("%I:%M")
if timeout[0] == "0":
print('{0}{1}{2}'.format('Leave today at ', timeout[-4:], 'pm'))
else:
print('{0}{1}{2}'.format('Leave today at ', timeout, 'pm'))
raw_input("press enter to exit")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment