- Feature Articles
- CodeSOD
- Error'd
-
Forums
-
Other Articles
- Random Article
- Other Series
- Alex's Soapbox
- Announcements
- Best of…
- Best of Email
- Best of the Sidebar
- Bring Your Own Code
- Coded Smorgasbord
- Mandatory Fun Day
- Off Topic
- Representative Line
- News Roundup
- Editor's Soapbox
- Software on the Rocks
- Souvenir Potpourri
- Sponsor Post
- Tales from the Interview
- The Daily WTF: Live
- Virtudyne
Admin
Why is the first function called 'GetTimeStamp'? It's not getting the timestamp, it's formatting a timestamp that its caller is passing in.
Oh, and frist!
Edit Admin
99 milliseconds should be enough for anyone.
Edit Admin
Copy pasta is the favorite food of bad programmers everywhere.
Admin
What amazes me about this kind of thing, so constantly, is that .NET comes with the most “batteries included” functions for so many things, date/time handing being exceptionally rich. But a lot of junior devs don’t bother to learn the framework, or maybe spend a minute in a search engine asking “has someone else in the history of programming ever solved this problem before?”
Admin
Hmm, a one-liner that does the same.
private string FileTimeStamp(DateTime param) { return param.Year.ToString() + "-" + ((param.Month < 10) ? "0" : "") + param.Month.ToString() + "-" + ((param.Day < 10) ? "0" : "") + param.Day.ToString() + " " + ((param.Hour < 10) ? "0" : "") + param.Hour.ToString() + ":" + ((param.Minute < 10) ? "0" : "") + param.Minute.ToString() + ":" + ((param.Second < 10) ? "0" : "") + param.Second.ToString() + "." + ((param.Millisecond < 10) ? "0" : "") + param.Millisecond.ToString(); }
Gotta be right?
Admin
Maybe this code was ported from a language that doesn't have good formatting built-in like .NET, and the ones doing the porting wanted to be as hands-off as possible, just a theory. Think about it - if you need the new system to behave exactly as the old system, you're gonna need to keep that milliseconds bug in there :-)
Edit Admin
string retDate = param.Year.ToString() + "-";
TRWTF is they didn't use
var
there, right?Edit Admin
That attitude will not get you any second dates (of the woman kind)
Admin
This is clearly auto-generated code which was perfectly concise in its original form. I'll wager milliseconds were a later addition and were simply tacked onto the end of a list somewhere, in the full knowledge that any inconsistent formatting will never get picked up in testing and whatever unit tests currently exist continued to pass. The generated strings are unique and that's good enough. If a system level bug occurs, then the blame is shared with whatever code expects milliseconds with up to four leading zeros. If an inode falls in the forest and nobody reads it, does it really exist? No.
That or it's LLM generated, in which case the prompter is clearly a 1000x high flyer who will already be a favourite before the consequences can come back to bite them
Admin
Actually I wouldn't have been at all surprised if the second version had the millisecond bug fixed.
That would be a typical maintenance scenario of making sure you don't "break" any existing use cases and fixing only the one you need.
Edit Admin
It's a shame the second function wasn't called
GetTimeStampNew
.