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

      Sunshine And March Vibes (2025 Wallpapers Edition)

      May 30, 2025

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

      May 30, 2025

      How To Fix Largest Contentful Paint Issues With Subpart Analysis

      May 30, 2025

      How To Prevent WordPress SQL Injection Attacks

      May 30, 2025

      Does Elden Ring Nightreign have crossplay or cross-platform play?

      May 30, 2025

      Cyberpunk 2077 sequel enters pre-production as Phantom Liberty crosses 10 million copies sold

      May 30, 2025

      EA has canceled yet another game, shuttered its developer, and started more layoffs

      May 30, 2025

      The Witcher 3: Wild Hunt reaches 60 million copies sold as work continues on The Witcher 4

      May 30, 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

      How Remix is shaking things up

      May 30, 2025
      Recent

      How Remix is shaking things up

      May 30, 2025

      Perficient at Kscope25: Let’s Meet in Texas!

      May 30, 2025

      Salesforce + Informatica: What It Means for Data Cloud and Our Customers

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

      Does Elden Ring Nightreign have crossplay or cross-platform play?

      May 30, 2025
      Recent

      Does Elden Ring Nightreign have crossplay or cross-platform play?

      May 30, 2025

      Cyberpunk 2077 sequel enters pre-production as Phantom Liberty crosses 10 million copies sold

      May 30, 2025

      EA has canceled yet another game, shuttered its developer, and started more layoffs

      May 30, 2025
    • Learning Resources
      • Books
      • Cheatsheets
      • Tutorials & Guides
    Home»News & Updates»CodeSOD: Halfway to a Date

    CodeSOD: Halfway to a Date

    January 16, 2025

    Roger took on a contract to fix up a PHP website. During the negotiations, he asked some questions about the design, like, “Is it object-oriented or more procedural?” “No, it’s PHP,” said the developer.

    Which about sums it up, I suppose. Have some date handling code:

    function MnameToMnumber($mname) //takes month name 'January' and returns month number '01'
            {
            if($mname == 'January'){$mnum = '01';}
            elseif($mname == 'February'){$mnum = '02';}
            elseif($mname == 'March'){$mnum = '03';}
            elseif($mname == 'April'){$mnum = '04';}
            elseif($mname == 'May'){$mnum = '05';}
            elseif($mname == 'June'){$mnum = '06';}
            elseif($mname == 'July'){$mnum = '07';}
            elseif($mname == 'August'){$mnum = '08';}
            elseif($mname == 'September'){$mnum = '09';}
            elseif($mname == 'October'){$mnum = '10';}
            elseif($mname == 'November'){$mnum = '11';}
            elseif($mname == 'December'){$mnum = '12';}
            return $mnum;
            }
    
    function MnumberToMname($mname) //takes month number '01' and returns month name '01'
            {
            if($mnum= '01'){$mname = 'January';}
            elseif($mnum= '02'){$mname = 'February';}
            elseif($mnum= '03'){$mname = 'March';}
            elseif($mname == 'April'){$mnum = '04';}
            elseif($mnum= '05'){$mname = 'May';}
            elseif($mnum= '06'){$mname = 'June';}
            elseif($mnum= '07'){$mname = 'July';}
            elseif($mnum= '08'){$mname = 'August';}
            elseif($mnum= '09'){$mname = 'September';}
            elseif($mnum= '10'){$mname = 'October';}
            elseif($mnum= '11'){$mname = 'November';}
            elseif($mnum= '12'){$mname = 'December';}
            return $mname;
            }
    
    

    So, for starters, I “love” the use of Whitesmiths indenting. I don’t think I’ve seen this in the wild. (I predict the comments section will be links to articles where I have seen this in the wild).

    Beyond that, there’s nothing terribly surprising here, in terms of bad date handling code, with a few small exceptions. First is their insistence on the conversion itself being stringly typed: January isn’t month 1, but "01".

    But more notable: MnumberToMname just doesn’t work. They’re using the assignment operator instead of the equality operator. At least, for all the cases where they’re doing the correct comparison direction. A stray “name to number” conversion is lurking in April. Not that it matters- this will always return January.

    [Advertisement]
    Keep the plebs out of prod. Restrict NuGet feed privileges with ProGet. Learn more.

    Source: Read More 

    Hostinger
    Facebook Twitter Reddit Email Copy Link
    Previous ArticleFOSS Weekly #25.03: Mint 22.1 Released, AI in VLC, Dual Boot Myths, Torvalds’ Guitar Offer and More
    Next Article Bit – modernized git CLI

    Related Posts

    News & Updates

    Does Elden Ring Nightreign have crossplay or cross-platform play?

    May 30, 2025
    News & Updates

    Cyberpunk 2077 sequel enters pre-production as Phantom Liberty crosses 10 million copies sold

    May 30, 2025
    Leave A Reply Cancel Reply

    Hostinger

    Continue Reading

    The Top 10 Generative AI Tools to Ace the New Era

    Web Development

    Microsoft loses OpenAI exclusive cloud provider status to $500 billion Stargate project — as the ChatGPT maker races to hoist the AGI flag first

    News & Updates

    Error’d: Infallabella

    Development

    Baby Duck Syndrome: What It Means and How to Manage It

    Development

    Highlights

    Development

    Mirai Botnet Variant Exploits Four-Faith Router Vulnerability for DDoS Attacks

    January 8, 2025

    A Mirai botnet variant has been found exploiting a newly disclosed security flaw impacting Four-Faith…

    How Multisensory Design Impacts Culinary Experiences

    June 17, 2024

    Ex-Air Guardsman Sentenced to 15 Years for Leaking Top-Secret U.S. Military Intel on Social Media

    November 15, 2024

    Google DeepMind Introduces Genie 2: An Autoregressive Latent Diffusion Model for Virtual World and Game Creation with Minimal Input

    December 5, 2024
    © DevStackTips 2025. All rights reserved.
    • Contact
    • Privacy Policy

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