- 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)