#!/usr/bin/python

# This is a program for calculating time sheets, which, as all of us that have had to do such a thing know, is a pain. I thus dedicate this piece of software to my love Amber. May it help you LOTS.

# This software is the intelectual property of Solomon Latham, but can be distributed freely. Changes are welcome, as are coments, as long as credit is given where due. 

# This is my first attempt at programing, and thus things that can and should be done in a more elegant way, well, will just have to suffer my ignorance untill I know better. As such, this software is distributed withount any guarantee of any kind, not even that it will work. If it turnes your computer into a brainless piece of moosh, or makes it stand up and run as far as it can, tough. But do tell me if that happens, I would love to know about it, if for no other reason then to make me laugh. 
# For those of you that might wonder, it has been writen with pyton 2.3 under debian linux. It has not been tested under any previous python releases as of Noveber 1st 2004 UT, date of the release of this alpha version.

# For comments, I can be contacted at the following email address: lathams@seattleu.edu

# For To Do list and fixes from this perticulare release, please go to end of file.

# Now that the formalities are out of the way, enjoye!

print "Welcome to the Time Sheet Calculator version 0.1.4"
print "This program works on a 24 hrs base!"
print "To input Hours, please use the following standard: 8 AM ==> 8; 2 PM ==> 14"
print "To input Minuts, simply inputing minuts will work: 20 min ==> 20"

# Ingredients:

while 1:
	try:
		STimeHrs = input ("Put Start Time Hours Here: ")
		break
	except NameError:
		print "That's not a number. Please try again."

while 2:
	try:
		STimeMin = input ("Put Start Time Minuts Here: ")
		break
	except NameError:
		print "That's not a number. Please try again."

while 3:
	try:
		ETimeHrs = input ("Put End Time Hours Here: ")
		break
	except NameError:
		print "That's not a number. Please try again."

while 4:
	try:
		ETimeMin = input ("Put End Time Minuts Here: ")
		break
	except NameError:
		print "That's not a number. Please try again."

while 5:
	try:
		BTimeHrs = input ("Put TOTAL Break Time Hours Here: ")
		break
	except NameError:
		print "That's not a number. Please try again."
		
while 6:
	try:
		BTimeMin = input ("Put TOTAL Break Time Minuts Here: ")
		break
	except NameError:
		print "That's not a number. Please try again."
print

# Formula:

# First change all hours into minuts
MSTimeHrs = STimeHrs*60
METimeHrs = ETimeHrs*60
MBTimeHrs = BTimeHrs*60

# Then add those hours minuts to the minuts themselves
TotalStimeMin = MSTimeHrs+STimeMin
TotalETimeMin = METimeHrs+ETimeMin
TotalBTimeMin = MBTimeHrs+BTimeMin

# Then substract from the end time the begining time and the break time
# This is Total Time in Minuts
TTM = TotalETimeMin-TotalStimeMin-TotalBTimeMin
print "This is the Total Time in Minuts:"
if TTM < 0:
	NxTTM = TTM+24*60		#Next Total Time in Minuts
	print NxTTM, "minuts"
else:
	print TTM, "minuts" 
print

# If we were to print TTM, then the result would only be in minuts, but we want that in hours and minuts.

# Since python is cool like that, it alows us not to worry about extra giberish after the decimal, so the total amount of hours can be calculated straight from Total Time in Minuts, thus giving us TTHRS ==> Total Time in Hours.
TTHRS = TTM/60
print ("and here is the same number but in hours and minuts:")

# If the working schedual is not on a morning to afternoon shift, but is on a afternoon to morning shift, then the math as presented is not going to work, so the solution is to add 24 hours to the negative number received.

if TTHRS < 0:
	NiTTHRS = TTHRS + 24
	print NiTTHRS, "hours"

else:
	print TTHRS, "hours"

# To calculate the amount of minuts only, take the total amount of minuts (TTM), substract the total amount of hours in minuts (TTHRS*60=TTHRSMin), and voila,we now have New Total Time in Minuts.
TTHRSMin = TTHRS*60
NTTMin = TTM-TTHRSMin
print NTTMin, "minuts"

print
print "Have a good day! ;^)"

# Fixes and improvements:
# Version 0.1.4
# Fixed more typos.
# Made the logic in the math more understandable for the hacker trying to make sence out of this script.
# Added support for start time on day previouse to end time, as long as it is still contained with in a 24 hour time period.
# Fixed input NameError problem. If somebody accidentaly types a letter instead of a numeral, the script shouldn't crash anymore.
# Removed the "alpha" denomination, since this script can now stand by itself as a "working" program.

# Version 0.1.3a
# Can now be run using ./filename, as long as user did: $chmod +x filename and this is run under a *nix or *bsd.
# Added Fixes list & Todo list.

# Version 0.1.2a
# Handles minuts conversion in a more elegant way.
# Cleaned up layout.

# Version 0.1.1a
# Fixed a couple of tipos.
# Program now runs giving accurate Total Amount of Time in Minuts only.
# Handles hours and minuts, but minuts are still buggy.

# To Do List (bugs & such):
# The inputing method of first inputing hours then minuts is not to my, and others, satisfaction, and thus will be changed to a true military standard, ie: 12.45 instead of 12 & 45 (Mike, you are the guilty one for my doing this... ;^p )
# In the long run, I want this program to be able to handle one week at a time, instead of being limited by the single day aproche.
# GUI, ahhhhhh the world of GUI... Soon, I hope.
