I have a question. I have a class that's supposed to represent 24-hour time. It has fields for hours, minutes, and seconds. Now, the problem is to write two functions. The first, seconds since midnight was easy. Just multiply and add. But the second one, Time since Time which returns a new Time, and is fed a time is supposed to work the same way. If given a Time with Hours, Minutes, and Seconds all zero it will return a copy of this. If not, it will return the amount of time that has passed since the inputted time. So, for example. if this is 10:00:00 and the input time is 05:00:00 then it will return a new time of 05:00:00. Another example: if this is 20:00:00 and the input is 15:00:00 the return will be 5:00:00. But, the problem is when the inputted time is greater than this. For example, if this is 05:00:00 and the input is 10:00:00 then what should it return? Or an other example, if this is something, say 10:00:00 and the input is 23:59:00, what then? And yes, those last examples should return something, but i don't know what. I realize this is probably very easy, but I seem to be having a block or what ever its called.
That's up to you. Either return a negative time or throw an exception, it depends on the application of the Time-class.
Or, if it's just a time without a date, assume it's the [i]next[/i] occurrence of that time if it's numerically less than the current time. If it's 23:59, the time 00:01 isn't in the past, it's two minutes in the future.
[QUOTE=Wyzard;28974234]Or, if it's just a time without a date, assume it's the [i]next[/i] occurrence of that time if it's numerically less than the current time. If it's 23:59, the time 00:01 isn't in the past, it's two minutes in the future.[/QUOTE]
That is, in fact what my teacher said, pretty much in those words. Thank you. For some reason, I wasn't understanding the that 00:01 is in fact two minutes after 23:59. Your post cleared that up for me. Thanks. Now that I understand that, could you possibly explain how to do it? I understand that for the normal cases I would simply do Inputtime-thistime, but what about for cases such as what you mentioned? 23:59 - 00:01 (assuming you can subtract time) would be much more than just two minutes. Do you understand?
Sorry, you need to Log In to post a reply to this thread.