Can somebody help me understand what does this function do? And also if there are any logical or syntactic errors in the function.
I was told that there are 2 bugs in the code. I can only think of 1 which is below:
1. In the first while loop in substr function the starting should be from 0 and not 1.
Can somebody correct me if I am wrong?
Much Obliged.
unsigned long normalise(unsigned long input_time)
{
bool finished;
// This produces a formatted time string like:
// Fri_Nov_25_18:22:48_1986
string str_time = format_time( input_time );
while( str_time.substr(1,3) != "Sun")
{
input_time -= 24*60*60;
str_time = format_time( input_time );
}
while( str_time.substr(11,2) != "00" )
{
input_time -= 60*60;
str_time = format_time( input_time );
}
while( str_time.substr(14,2) != "00")
{
str_time = format_time( input_time );
input_time -= 60;
}
while( str_time.substr(17,2) != "00")
{
input_time -= 1;
str_time = format_time( input_time );
}
return input_time;
}