Ask your own question, for FREE!
Computer Science 29 Online
OpenStudy (anonymous):

I need to write a function night_hours(start_time, end_time, night_start, night_end) that calculates how many hours between start_time and end_time are within the range of night_start to night_end, or calculate how many night hours there are between start_time and end_time. I will appreciate any help. Thanks :)

OpenStudy (rsmith6559):

In general terms ( because I don't know what language, what modules can be used or the data type of the return value): start_time -> end_time would be the difference (difference suggests subtraction) of the two. Same thing with the night_*. Then make sure that the night_* is larger than the *_time differnce. What gets fun is night suggests that one or both of the night_* values could go past midnight and need some adjusting. And any of the minutes could need to borrow an hour, but the helper function find_difference( begin, end ) could/should handle that. If you can use a module/library that will convert the times to numbers, it would be even simpler, but the past midnight problem remains.

jaynator495 (jaynator495):

There is not enough information to answer this well, please provide a language, thank you.

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!