简体   繁体   中英

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

So I have a physical chart 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM