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

      10 Benefits of Hiring a React.js Development Company (2025–2026 Edition)

      August 13, 2025

      From Line To Layout: How Past Experiences Shape Your Design Career

      August 13, 2025

      Hire React.js Developers in the US: How to Choose the Right Team for Your Needs

      August 13, 2025

      Google’s coding agent Jules gets critique functionality

      August 13, 2025

      The best smartphones without AI features in 2025: Expert tested and recommended

      August 13, 2025

      GPT-5 was supposed to simplify ChatGPT but now it has 4 new modes – here’s why

      August 13, 2025

      Gemini just got two of ChatGPT’s best features – and they’re free

      August 13, 2025

      I found the easiest way to send files between my Android phone and desktop – and it’s free

      August 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

      Laravel Boost is released

      August 13, 2025
      Recent

      Laravel Boost is released

      August 13, 2025

      Frontend Standards for Optimizely Configured Commerce: Clean & Scalable Web Best Practices

      August 13, 2025

      Live Agent Escalation in Copilot Studio Using D365 Omnichannel – Architecture and Use Case

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

      OpenAI’s Sam Altman: GPT-5 fails to meet AGI standards amid Microsoft’s fading partnership — “it’s still missing something”

      August 13, 2025
      Recent

      OpenAI’s Sam Altman: GPT-5 fails to meet AGI standards amid Microsoft’s fading partnership — “it’s still missing something”

      August 13, 2025

      You Think You Need a Monster PC to Run Local AI, Don’t You? — My Seven-Year-Old Mid-range Laptop Says Otherwise

      August 13, 2025

      8 Registry Tweaks that will Make File Explorer Faster and Easier to Use on Windows 11

      August 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?

    [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

    The best smartphones without AI features in 2025: Expert tested and recommended

    August 13, 2025
    News & Updates

    GPT-5 was supposed to simplify ChatGPT but now it has 4 new modes – here’s why

    August 13, 2025
    Leave A Reply Cancel Reply

    For security, use of Google's reCAPTCHA service is required which is subject to the Google Privacy Policy and Terms of Use.

    Continue Reading

    Sitecore Search Source Types – Part I

    Development

    “Some Suspect They Might Already Exist” — NVIDIA’s Chief Security Officer Doubles Down on the Lack of Kill Switches, Backdoors, and Spyware in Its GPUs

    News & Updates

    Distribution Release: RefreshOS 2.5

    News & Updates

    CVE-2025-1562 – WooCommerce FunnelKit Plugin Unauthenticated Remote Code Execution

    Common Vulnerabilities and Exposures (CVEs)

    Highlights

    WWDC 2025: Apple to Revamp SwiftUI for Richer App Experiences

    June 4, 2025

    WWDC 2025: Apple to Revamp SwiftUI for Richer App Experiences

    During the upcoming WWDC 2025, in addition to unveiling updates to its major operating systems, Apple is also expected to introduce a revised SwiftUI framework aimed at streamlining the development pr …
    Read more

    Published Date:
    Jun 04, 2025 (3 hours, 18 minutes ago)

    Vulnerabilities has been mentioned in this article.

    CVE-2022-23494

    Out of the blue, GTA V is finally approved for release in Saudi Arabia — and it’s coming soon

    July 4, 2025

    CVE-2025-53519 – Advantech iView Reflected Cross-Site Scripting (XSS) Vulnerability

    July 10, 2025

    April 2025 Wallpapers Edition

    April 2, 2025
    © DevStackTips 2025. All rights reserved.
    • Contact
    • Privacy Policy

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