Skip navigation.
Home

Rolling your own Date/Time functions

Bad Architecture

What do you do when there are just too many working hours in the day? Re-invent some PHP functions. While you're at it also add some global variable requirements to make sure free time doesn't happen in the future.

Comments are submitter's:

<?php
//all this to do a strtotime("+1 month", $time) using global vars... ewh.
function month_adv() {
       Global
$month, $month_adv, $num_day_adv, $month_inc_adv;
       if (
$month == "January") {
               
$month_adv = "February";
               
$num_day_adv = "28";
               
$month_inc_adv = "02";
       }
       if (
$month == "February") {
               
$month_adv = "March";
               
$num_day_adv = "31";
               
$month_inc_adv = "03";
       }
       if (
$month == "March") {
               
$month_adv = "April";
               
$num_day_adv = "30";
               
$month_inc_adv = "04";
       }
       if (
$month == "April") {
               
$month_adv = "May";
               
$num_day_adv = "31";
               
$month_inc_adv = "05";
       }
       if (
$month == "May") {
               
$month_adv = "June";
               
$num_day_adv = "30";
               
$month_inc_adv = "06";
       }
       if (
$month == "June") {
               
$month_adv = "July";
               
$num_day_adv = "31";
               
$month_inc_adv = "07";
       }
       if (
$month == "July") {
               
$month_adv = "August";
               
$num_day_adv = "31";
               
$month_inc_adv = "08";
       }
       if (
$month == "August") {
               
$month_adv = "September";
               
$num_day_adv = "30";
               
$month_inc_adv = "09";
       }
       if (
$month == "September") {
               
$month_adv = "October";
               
$num_day_adv = "31";
               
$month_inc_adv = "10";
       }
       if (
$month == "October") {
               
$month_adv = "November";
               
$num_day_adv = "30";
               
$month_inc_adv = "11";
       }
       if (
$month == "November") {
               
$month_adv = "December";
               
$num_day_adv = "31";
               
$month_inc_adv = "12";
       }
       if (
$month == "December") {
               
$month_adv = "January";
               
$num_day_adv = "31";
               
$month_inc_adv = "01";
       }
}
//END Month Advance
?>

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

Let me guess, the $month_adv was introduced after every date being advanced till december. This is the second WTF after the whole function at all: "WTF (where) are the else statements" or "WTF (why) must all months be checked even when the first hits"?

Hey... pity about leap years...

Oh man... this one hurts... xDD

Never heard of the switch statement anyways?

Oh yes, and those double quotes... forcing the PHP parser to waste its time checking for variable substitutions in plain strings... that's another way of using the idle CPU time. :)

What also hurts is the usage of globals. Functions that return something suck, yeah!

Reading this really causes physical pain. I'm not a good programmer but even I would produce such a WTF. And, yes, I love the hardcoded 28 days for February, too :)

OK... so if they think they need this function why did they waste CPU time by using mulitiple IF statements when and else if would be better... so yea..

definatly added some snickers in my day... *snicker*

Seriously, WTF?!?

Seriously, WTF?!?

Seriously, WTF?!?

Post new comment




*

  • Web and e-mail addresses are automatically converted into links.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <pre> <p> <br /> <br>