Shocked art fans are all saying the same thing after seeing the original 'Great Wave' painting
Which? reveals the best supermarket garden furniture for 2025 - from Aldi, Asda, Sainsburys and more
Plane passenger's hilarious way of getting a nap on a Ryanair flight - Would you try it?
Rugby playing dad-of-three hit by deadly motor neurone disease - the first sign was a common symptom missed a DECADE earlier
Katie Price brands herself 'fake, ugly and disgusting' as she reacts to video of herself getting surgery in Turkey - but insists she still wants MORE work done - as fans rage 'enough is enough'
Hertsmere council leader 'delighted' as complaint against him dismissed
Zac Efron showcases shock new look as fans notice major hair transformation
£250m wiped off value of UK pork producer after sickening secret recordings show helpless piglets being 'beaten to death'
The mystery electric substation fires that 'bear the hallmarks of Russian sabotage': How spate of suspicious blazes are 'straight out of playbook' of Putin's GRU spy wing
Universe Expected To Decay Much Sooner Than Previously Thought
Read more of this story at Slashdot.
Erin Patterson mushroom murder trial LIVE updates: Fungi expert tells court disturbingly easy way death cap mushrooms can be found
Woman splashed out on lavish lifestyle and expensive holidays after stealing £189k from her work
Essex Tesco petrol station closes for 12 days for major update
Linus Torvalds goes back to a mechanical keyboard after making too many typos
Linux kernel project boss Linus Torvalds has re-joined the ranks of full-size mechanical keyboard aficionados.…
Mars may have vast underground oceans and enough H<sub>2</sub>O to make it a water world
Mars may still be home to oceanic quantities of liquid water, according to a recent paper published by the National Science Review.…
American oil magnate, his wife and two sons indicted over $300M crime scheme linked to Mexican cartels
Police looking for these two men after brawl outside Essex restaurant
Woman's car stolen after gang pressured her into handing over keys
CodeSOD: Exactly a Date
Alexandar sends us some C# date handling code. The best thing one can say is that they didn't reinvent any wheels, but that might be worse, because they used the existing wheels to drive right off a cliff.
try { var date = DateTime.ParseExact(member.PubDate.ToString(), "M/d/yyyy h:mm:ss tt", null); objCustomResult.PublishedDate = date; } catch (Exception datEx) { }member.PubDate is a Nullable<DateTime>. So its ToString will return one of two things. If there is a value there, it'll return the DateTimes value. If it's null, it'll just return an empty string. Attempting to parse the empty string will throw an exception, which we helpfully swallow, do nothing about, and leave objCustomResult.PublishedDate in whatever state it was in- I'm going to guess null, but I have no idea.
Part of this WTF is that they break the advantages of using nullable types- the entire point is to be able to handle null values without having to worry about exceptions getting tossed around. But that's just a small part.
The real WTF is taking a DateTime value, turning it into a string, only to parse it back out. But because this is in .NET, it's more subtle than just the generation of useless strings, because member.PubDate.ToString()'s return value may change depending on your culture info settings.
Which sure, this is almost certainly server-side code running on a single server with a well known locale configured. So this probably won't ever blow up on them, but it's 100% the kind of thing everyone thinks is fine until the day it's not.
The punchline is that ToString allows you to specify the format you want the date formatted in, which means they could have written this:
var date = DateTime.ParseExact(member.PubDate.ToString("M/d/yyyy h:mm:ss tt"), "M/d/yyyy h:mm:ss tt", null);But if they did that, I suppose that would have possibly tickled their little grey cells and made them realize how stupid this entire block of code was?