I'm trying to write a program for myself, allowing me to enter my schedule for work and have it calculate the total hours for the week. I'm storing the hours and minutes for each day as a byte, since the maximum value for either will never exceed 24. Since I frequently work until midnight (or later) I need it to be able to handle that. This is where I'm having issues. If I only work until midnight then I'm fine, since I made is so that midnight is actually read as 24 (whereas in real military time, midnight is the 0th hour.) So for example, a 3:30 pm to midnight shift will properly show as 8 hours and 30 minutes, but 3:30 pm to 12:01 am will show as a 9 hours and 227 minutes.
I need to figure out a better way to determine the number of hours between a given start and end time, taking into account that the end time might be past midknight, or that for a short time the start time might actually be after the end time. I want to make sure the byte doesn't loop around and show something like 250 hours. Any suggestions?
I need to figure out a better way to determine the number of hours between a given start and end time, taking into account that the end time might be past midknight, or that for a short time the start time might actually be after the end time. I want to make sure the byte doesn't loop around and show something like 250 hours. Any suggestions?
Comment