|
Be very careful with code like this. You think it's the same 1000 lines but you may find one line has been changed. Seen this rubbish many times before, if you refractor to make sense of it, you'll miss that one line.
"You get that on the big jobs."
|
|
|
|
|
Yep I was worried about that too and I know the differences. And thinking of future I redesigned the entire page. Now even I need to change its only one function.
|
|
|
|
|
As Rob says, make sure you are entirely sure of any changes between blocks and that they are maintained.
I have encountered this many times while translating old classic asp applications to newer dotNet. I found that by splitting each of the cases into a separate text file and then running diffs on them tends to make the job much easier. The good part is that most devs who have done this used copy-paste and then made their modifications, so there is some hope for them yet...
I wasn't, now I am, then I won't be anymore.
|
|
|
|
|
I was going to suggest exactly this little trick. It can really help with refactoring old crap.
|
|
|
|
|
Following from rob, take the three code blocks and diff them.
Panic, Chaos, Destruction. My work here is done.
Drink. Get drunk. Fall over - P O'H
OK, I will win to day or my name isn't Ethel Crudacre! - DD Ethel Crudacre
I cannot live by bread alone. Bacon and ketchup are needed as well. - Trollslayer
Have a bit more patience with newbies. Of course some of them act dumb - they're often *students*, for heaven's sake - Terry Pratchett
|
|
|
|
|
Or even better, throw them away. Rewriting from scratch can be less work in such cases.
And from the clouds a mighty voice spoke: "Smile and be happy, for it could come worse!"
And I smiled and was happy And it came worse.
|
|
|
|
|
|
private string GetTime(string strShiftCode, string strTime)
{
string strReturn = "";
switch (strTime)
{
case "01":
strReturn = "AM";
break;
case "02":
strReturn = "AM";
break;
case "03":
strReturn = "AM";
break;
case "04":
strReturn = "AM";
break;
case "05":
strReturn = "AM";
break;
case "06":
strReturn = "AM";
break;
case "07":
strReturn = "AM";
break;
case "08":
strReturn = "AM";
break;
case "09":
strReturn = "AM";
break;
case "10":
strReturn = "AM";
break;
case "11":
strReturn = "AM";
break;
case "12":
strReturn = "PM";
break;
case "13":
strReturn = "PM";
break;
case "14":
strReturn = "PM";
break;
case "15":
strReturn = "PM";
break;
case "16":
strReturn = "PM";
break;
case "17":
strReturn = "PM";
break;
case "18":
strReturn = "PM";
break;
case "19":
strReturn = "PM";
break;
case "20":
strReturn = "PM";
break;
case "21":
strReturn = "PM";
break;
case "22":
strReturn = "PM";
break;
case "23":
strReturn = "PM";
break;
case "24":
strReturn = "PM";
break;
}
return strReturn;
}
Found this one on one of the project assigned to me today.... It really is about quality control..
One variable passed is never been used in function and do I really need a function ?
My solution :
string strReturn = Int32.Parse(strTime.Trim())<12 ? "AM" : "PM";
Zen and the art of software maintenance : rm -rf *
Math is like love : a simple idea but it can get complicated.
|
|
|
|
|
In any case I would also look at all places where the function is called. There this unused parameter must be passed. It's better when you find out what this 'ShiftCode' may have been intended for.
And from the clouds a mighty voice spoke: "Smile and be happy, for it could come worse!"
And I smiled and was happy And it came worse.
|
|
|
|
|
It's also wrong : "24" is "AM"
Cheers
If you can read this, you don't have Papyrus installed
|
|
|
|
|
And that again may also be wrong. Are the hours not enumerated 0 - 23, totally VB unfriendly?
And from the clouds a mighty voice spoke: "Smile and be happy, for it could come worse!"
And I smiled and was happy And it came worse.
|
|
|
|
|
The application is used to monitor Robots in factory so may be hour 24 is AM for them... I don't speak Robolang yet ...
Zen and the art of software maintenance : rm -rf *
Math is like love : a simple idea but it can get complicated.
|
|
|
|
|
Yes, you and I (and probalby most people) would calculate that way.
In the past I have once or twice seen the time expressed as 24:xx.
Anyhoo, if you inspect the code you will see 11 AM's and 13 PM's.
Cheers
If you can read this, you don't have Papyrus installed
|
|
|
|
|
Time and dates can be hell, even if you have a decent framework at your disposal. If you do such things on the fly: Good luck.
And from the clouds a mighty voice spoke: "Smile and be happy, for it could come worse!"
And I smiled and was happy And it came worse.
|
|
|
|
|
You never get "24" it's "00"
|
|
|
|
|
That depends entirely on the input, we're not dealing with a real time format here.
As said by others here, thse method is wrong in many respects.
My comment denoted that there are 11 "AM" entries and 13 "PM" entries.
So if "24" is input, the output should logically be "AM", not "PM".
Cheers
If you can read this, you don't have Papyrus installed
|
|
|
|
|
ISO 8601 allows 24:00 as the end of the day, so it would be PM; AM starts at 00:00 (not that ISO 8601 recognizes AM/PM of course).
|
|
|
|
|
Do 24:00 and 00:00 occur at the same time then, just different notations?
|
|
|
|
|
Yes, different notations for the same timepoint.
|
|
|
|
|
Same timepoint, but different datepoint
modified 19-Nov-18 21:01pm.
|
|
|
|
|
The Army (at least) took 2400 as the end of the day...and never acknowledged 0000 as existing. :p
|
|
|
|
|
Then one second after that would be 240001 or 000001?
|
|
|
|
|
000001
But we just started the new logs at 0001Z. That minute inbetween was just ignored.
Actually, come to think of it, we never used 2400Z, either. The day ended at 2359Z and the next started at 0001Z. :p
|
|
|
|
|
If you are dealing with instantaneity, 12:00:00 and 24:00:00 (or 0:00:00, if you prefer) are neither AM nor PM: the first is Noon and the second is Midnight.
Just think of it as evolution in action.
|
|
|
|
|
But there is a fix for that issue...
string ampm = GetTime("Blahblahblah", strTime);
if (strTime = "24" && ampm = "PM")
{
ampm = "AM";
}
See! It's easy.
|
|
|
|