Essex family 'traumatised' after horror film trailers shown before Lilo and Stitch
Essex family 'traumatised' after horror film trailers shown before Lilo and Stitch
Dog walker ordered to pay compensation after sheep and lambs die
EastEnders icon Zoe Slater RETURNS to the soap as Michelle Ryan reprises her role after 20 years (and she's back for good!)
UK dumps £2.5 billion into fusion pipe dream that's already cost millions
UPDATED The UK government has just allocated another £2.5 billion to an ambitious fusion energy project without any indication it's progressed much beyond the planning stages.…
Denmark Tests Unmanned Robotic Sailboat Fleet
Read more of this story at Slashdot.
Essex Sainsbury's customer 'horrified' after spotting dirt and 'rotting fish' in seafood aisle
Identical Air India Dreamliner to one in devastating crash had mid air engine failure and was forced to make emergency landing in 2023
Australian woman dies after consuming too much caffeine
Minnesota assassin's chilling notepad seen for the first time as he makes astonishing poverty claim in court
Why you should NEVER criticise your ex in front of your children: Expert reveals why stars like Fern Britton and Kim Kardashian are right to be 'kind' about their former husbands
Infamous Dem-run city descends into Mad Max hellscape as streets are filled with apocalyptic races and explosions
Remains found in bushland are confirmed to be those of missing teen Pheobe Bishop
Microsoft brings 365 suite on-prem as part of sovereign cloud push
Microsoft has created a version of its 365 productivity suite that runs on-premises, as part of a move to satisfy European regulations.…
CodeSOD: A Second Date
Ah, bad date handling. We've all seen it. We all know it. So when Lorenzo sent us this C# function, we almost ignored it:
private string GetTimeStamp(DateTime param) { string retDate = param.Year.ToString() + "-"; if (param.Month < 10) retDate = retDate + "0" + param.Month.ToString() + "-"; else retDate = retDate + param.Month.ToString() + "-"; if (param.Day < 10) retDate = retDate + "0" + param.Day.ToString() + " "; else retDate = retDate + param.Day.ToString() + " "; if (param.Hour < 10) retDate = retDate + "0" + param.Hour.ToString() + ":"; else retDate = retDate + param.Hour.ToString() + ":"; if (param.Minute < 10) retDate = retDate + "0" + param.Minute.ToString() + ":"; else retDate = retDate + param.Minute.ToString() + ":"; if (param.Second < 10) retDate = retDate + "0" + param.Second.ToString() + "."; else retDate = retDate + param.Second.ToString() + "."; if (param.Millisecond < 10) retDate = retDate + "0" + param.Millisecond.ToString(); else retDate = retDate + param.Millisecond.ToString(); return retDate; }Most of this function isn't terribly exciting. We've seen this kind of bad code before, but even when we see a repeat like this, there are still special treats in it. Look at the section for handling milliseconds: if the number is less than 10, they pad it with a leading zero. Just the one, though. One leading zero should be enough for everybody.
But that's not the thing that makes this code special. You see, there's another function worth looking at:
private string FileTimeStamp(DateTime param) { string retDate = param.Year.ToString() + "-"; if (param.Month < 10) retDate = retDate + "0" + param.Month.ToString() + "-"; else retDate = retDate + param.Month.ToString() + "-"; if (param.Day < 10) retDate = retDate + "0" + param.Day.ToString() + " "; else retDate = retDate + param.Day.ToString() + " "; if (param.Hour < 10) retDate = retDate + "0" + param.Hour.ToString() + ":"; else retDate = retDate + param.Hour.ToString() + ":"; if (param.Minute < 10) retDate = retDate + "0" + param.Minute.ToString() + ":"; else retDate = retDate + param.Minute.ToString() + ":"; if (param.Second < 10) retDate = retDate + "0" + param.Second.ToString() + "."; else retDate = retDate + param.Second.ToString() + "."; if (param.Millisecond < 10) retDate = retDate + "0" + param.Millisecond.ToString(); else retDate = retDate + param.Millisecond.ToString(); return retDate; }Not only did they fail to learn the built-in functions for formatting dates, they forgot about the functions they wrote for formatting dates, and just wrote (or realistically, copy/pasted?) the same function twice.
At least both versions have the same bug with milliseconds. I don't know if I could handle it if they were inconsistent about that.
[Advertisement] Picking up NuGet is easy. Getting good at it takes time. Download our guide to learn the best practice of NuGet for the Enterprise.