While working on his company's reservation manager, Stephaan stumbled upon some PHP code that calculated the date values for tomorrow (`\$morgen`) and the day after tomorrow (`\$ubermorgen`). Something about the code struck him as ... wrong.

``` // FORMAT DATE // detect this day and this month (without 0) \$today = date("j") ; \$thismonth = date("n") ; \$manyday = date("t") ;

``````// define morgen and ubermorgen dates
if (\$manyday == 30 && \$today == 30) // for 30. from 30 days's month
{
\$morgen = 1 ;
\$morgenmonth = \$thismonth+1 ;
\$ubermorgen = 2 ;
\$ubermorgenmonth = \$thismonth+1 ;
}
elseif (\$manyday == 31 && \$today == 30) // for 30. from 31 days's month
{
\$morgen = 31 ;
\$morgenmonth = \$thismonth ;
\$ubermorgen = 1 ;
\$ubermorgenmonth = \$thismonth+1 ;
}
elseif (\$manyday == 29 && \$today == 28) // for 28 february
{
\$morgen = 29 ;
\$morgenmonth = \$thismonth ;
\$ubermorgen = 1 ;
\$ubermorgenmonth = \$thismonth+1 ;
}
elseif (\$manyday == 29 && \$today == 29) // for 29 february
{
\$morgen = 1 ;
\$morgenmonth = \$thismonth ;
\$ubermorgen = 2 ;
\$ubermorgenmonth = \$thismonth+1 ;
}
elseif (\$today == 30 && \$thismonth == 12) // for 30 december
{
\$morgen = 31 ; 2
\$morgenmonth = \$thismonth ;
\$ubermorgen = 1 ;
\$ubermorgenmonth = 1 ;
}
elseif (\$today == 31 && \$thismonth == 12) // for 31 december
{
\$morgen = 1 ;
\$morgenmonth = 1 ;
\$ubermorgen = 2 ;
\$ubermorgenmonth = 1 ;
}
elseif (\$today == 31) // for 31. from 31 days's month
{
\$morgen = 1 ;
\$morgenmonth = \$thismonth+1 ;
\$ubermorgen = 2 ;
\$ubermorgenmonth = \$thismonth+1 ;
}
else // normal days
{
\$morgen = \$today+1 ;
\$morgenmonth = \$thismonth ;
\$ubermorgen = \$today+2 ;
\$ubermorgenmonth = \$thismonth ;
}
``````

```

Feeling in an experimental mood, Stephaan decided to test the code. It worked for any date given on a leap year, but broke on February 27th of any other year. Typically, errors in date-calculating code happen on leap years, but in this instance it only worked perfectly during leap years.

Stephaan could think of several solutions. He could calculate `\$morgen` as `(\$today + 1) % \$manyday`. He could then create a function, `morgen(date)`, and write `ubermorgen(date)` with the recursive `morgen(morgen(date))`. However, PHP already has built-in functions for calculating dates, and could simply write `\$übermorgen = strtotime('+ 2 days')`.

But Stephaan did none of these things, as the code wasn't actually being referenced anywhere else in the application. `\$morgen` and `\$ubermorgen` were quietly put to pasture, and no one was the wiser.

[Advertisement] BuildMaster allows you to create a self-service release management platform that allows different teams to manage their applications. Explore how!