开发者

How to check if a time (minute/second) is in a given interval?

So I have a physical char开发者_如何学Got of time intervals (minute:second) which map to point values (for example: 9:59-10:10 = 59.7) and I need to write a program that tries to find out the point value for a given time (such as 10:02 would return 59.7).

I would also like to have the interval chart stored in a .properties file, so my other "calculators" are all consistent.

What would be the best way to program this?


One simple way would be to map the time to an integer - either number of seconds through the day (minutes * 60 + seconds) or just effectively "remove the colon" mapping 9:59 to 959, and 10:10 to 1010 (minutes * 100 + seconds).

Then each interval is just a pair of integers. If you have lots of intervals you may want to store them in a sorted list and perform a binary chop - if you don't have very many of them (or don't need to do this very often) then simply having a list of interval/value and walking through the list would be pretty simple.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜