Close Menu
    DevStackTipsDevStackTips
    • Home
    • News & Updates
      1. Tech & Work
      2. View All

      Sunshine And March Vibes (2025 Wallpapers Edition)

      May 13, 2025

      The Case For Minimal WordPress Setups: A Contrarian View On Theme Frameworks

      May 13, 2025

      How To Fix Largest Contentful Paint Issues With Subpart Analysis

      May 13, 2025

      How To Prevent WordPress SQL Injection Attacks

      May 13, 2025

      This $4 Steam Deck game includes the most-played classics from my childhood — and it will save you paper

      May 13, 2025

      Microsoft shares rare look at radical Windows 11 Start menu designs it explored before settling on the least interesting one of the bunch

      May 13, 2025

      NVIDIA’s new GPU driver adds DOOM: The Dark Ages support and improves DLSS in Microsoft Flight Simulator 2024

      May 13, 2025

      How to install and use Ollama to run AI LLMs on your Windows 11 PC

      May 13, 2025
    • Development
      1. Algorithms & Data Structures
      2. Artificial Intelligence
      3. Back-End Development
      4. Databases
      5. Front-End Development
      6. Libraries & Frameworks
      7. Machine Learning
      8. Security
      9. Software Engineering
      10. Tools & IDEs
      11. Web Design
      12. Web Development
      13. Web Security
      14. Programming Languages
        • PHP
        • JavaScript
      Featured

      Community News: Latest PECL Releases (05.13.2025)

      May 13, 2025
      Recent

      Community News: Latest PECL Releases (05.13.2025)

      May 13, 2025

      How We Use Epic Branches. Without Breaking Our Flow.

      May 13, 2025

      I think the ergonomics of generators is growing on me.

      May 13, 2025
    • Operating Systems
      1. Windows
      2. Linux
      3. macOS
      Featured

      This $4 Steam Deck game includes the most-played classics from my childhood — and it will save you paper

      May 13, 2025
      Recent

      This $4 Steam Deck game includes the most-played classics from my childhood — and it will save you paper

      May 13, 2025

      Microsoft shares rare look at radical Windows 11 Start menu designs it explored before settling on the least interesting one of the bunch

      May 13, 2025

      NVIDIA’s new GPU driver adds DOOM: The Dark Ages support and improves DLSS in Microsoft Flight Simulator 2024

      May 13, 2025
    • Learning Resources
      • Books
      • Cheatsheets
      • Tutorials & Guides
    Home»News & Updates»CodeSOD: Exactly a Date

    CodeSOD: Exactly a Date

    May 13, 2025

    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?

    <!– Easy Reader Version: I'm starting to think that dates aren't the problem, but strings. Text was a mistake. We should go back to cuneiform.

    [Advertisement]
    Utilize BuildMaster to release your software with confidence, at the pace your business demands. Download today!

    –>

    Source: Read More 

    Facebook Twitter Reddit Email Copy Link
    Previous ArticleCVE-2025-26662 – Apache Data Services Management Console Cross-Site Scripting Vulnerability
    Next Article nip4 is an image processing spreadsheet

    Related Posts

    News & Updates

    This $4 Steam Deck game includes the most-played classics from my childhood — and it will save you paper

    May 13, 2025
    News & Updates

    Microsoft shares rare look at radical Windows 11 Start menu designs it explored before settling on the least interesting one of the bunch

    May 13, 2025
    Leave A Reply Cancel Reply

    Continue Reading

    I can’t pick a favorite — the award-winning Razer Blade 16 or its new big sibling — but you can preorder both now

    News & Updates

    Artificial Empathy vs Artificial Intelligence

    Development

    Mysterious Windows 11 “actions” menu appears in latest preview build — here’s what it’s for

    News & Updates

    Universal Design Principles Supporting Operable Content – Low Physical Effort

    Development

    Highlights

    Development

    Harnessing Full-Text Search in Laravel

    February 17, 2025

    Explore Laravel’s built-in full-text search capabilities using whereFullText methods. Learn how to implement efficient search…

    DragonRank Exploits IIS Servers with BadIIS Malware for SEO Fraud and Gambling Redirects

    February 10, 2025

    Is AI a fad? 76% of researchers say scaling has “plateaued” — but firms like OpenAI continue splurging billions into a dead end

    March 28, 2025

    Godfather of AI and Elon Musk seemingly join forces to curb OpenAI’s evolution into a for-profit entity — potentially leaving the ChatGPT maker susceptible to outsider interference and hostile takeovers

    January 8, 2025
    © DevStackTips 2025. All rights reserved.
    • Contact
    • Privacy Policy

    Type above and press Enter to search. Press Esc to cancel.