I have a text file with records in it. I need to decide if the time (which is part of the record structure) is between 2 times (stored in strings) that represents the lower and upper range.
In the file the time is represented in 145540123456, which means 14 is the hour, 55 – minutes, 40 – seconds, 123456 – micrseconds accurate.
The upper and lower time that I get to decide if it is in the range, I get it as a string in the same format for instance “093000000000”. How do I make the calculation, do I need to do it with time_t and time library?
Note: I can’t use Boost.
The format you specify has the simple advantage that sorting these time-strings alpha-numerically will keep them in the correct order.
Therefore, using
strcmp(simple C function if using null-terminated char * buffers), or the comparison operators forstd::stringcan allow you to determine easily if a certain time string belongs to an interval.These methods can lead to very few calculations, if, for example, the first character of the strings you compare differs, since the standard functions should be smart enough to stop comparing the strings as soon as they have determined the result.