|
|
time_t normalise(time_t input_time)
{
bool finished;
// This produces a formatted time string like:
// Thu_Nov_24_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;
}
I think this is c++ and I'm just curious what this particular function does. Can anyone spot any errors in the particular code. Are there any other inefficiencies in the the code....
Is there another way to implement the code.
|
|
|
|
hi ace3333,
the code seem working fine for me.
that function working to convert the datetime data
Now() and convert it on the format that had been
remark on that function. please explain more what you
need.
|
|
|
|
|
|
Just wondering what the code does, I don't really understand what you said in the last post.
If you can run the code can you give me a sample input and output
|
|
|
|
It looks like
The first loop subtracts a day until you get to the previous Sunday.
The second loop subtracts an hour from the time until you get to midnight.
The third loop subtracts a minute from the time until you get to the beginning of the hour.
The fourth loop subtracts a second from the time until you get to beginning of the minute.
This should return:
a) If the input wasn't a Sunday should return the previous Sunday at midnight.
b) If it was a Sunday should return the current Sunday at midnight.
Possible changes could of course include removing the loops for the hour, minutes and seconds as you could just set those all to 00 in the string, (thus avoiding the worst case scenario of 11, 59 and 59 in your loops).
The first loop could probably be changed to a case/switch statement with different cases for the different days of the week.
The bool seems to be unused.
Looks like the substr for all the time comparisons is off by an index of 1.
semper fi...
|
|
|
|
Can i know what program is that?
cause I am having the same problem as well.
many thanks.
|
|
|
|
|
|
|
|