• (nodebb)
``````{
\$frist = '00';
}```
``````
• Nobody (unregistered)

Maybe they use just quarters: 0, 15, 30, 45. In this case padding is only needed for the 0. But the code is bad anyways.

• thegoryone (unregistered)

sprintf('%05.2f', \$min);

Done.

• Little Bobby Tables (unregistered)

Not so much brainfart as a head full of nothing but flatulence.

• TVJohn (unregistered)

Or perhaps minutes have to be recorded in units of 10 minutes or more. That would not be uncommon for something like time recording.

• Tom (unregistered)

I like how the if/else statement could just be replaced with: \$min = '00';

• Arthur (unregistered)

Am I seeing correctly? Aren't those 2 blocks (if and else) doing the same thing?

• (nodebb)

If only there were Date libraries with formatting....

• ooOOooGa (unregistered)

Well, if you zero pad a 3, you can easily tell which is the real data and which is the padding. But if you zero pad a 0 that causes data loss. How would you ever be able to get the original zero back?

• Bruce W (unregistered)

Have we ever thought of a WTF Score, for example the number of WTFs per line? This sample would set the bar pretty high.

The worst part is the curly brace on the same line as the if statement, instead of being on the next line where it belongs.

• Kevin (unregistered)

I'm looking really hard at that inner if/else clause, and I swear it does nothing whatsoever. Unless this is javascript and you've got to convert "twelvey" values into 12.

• (nodebb) in reply to Nobody

Maybe they use just quarters: 0, 15, 30, 45. In this case padding is only needed for the 0.

Yep. Good old YAGNI principle: You aren't gonna need it!

• Flips (unregistered)

If (\$hours==12) \$hours = 12 else \$hours = \$hours

redundancy is redundant

• I Am The Very Model (unregistered) in reply to Brian Boorman

Really? A formatting preference is worse than only padding some of the time, or pointlessly assigning \$hours the value it already holds?

• Wyrm (unregistered)

And I expect the coder to read your article and fix the code. if (\$min == 0) { if (\$hours == 12) { \$hours = 12; \$min = '00'; } else if(\$min == 1) { \$hours = \$hours; \$min = '01'; } else if(\$min == 3) { \$hours = \$hours; \$min = '03'; } else if(\$min < 10) { \$hours = \$hours; \$min = '0' + \$min; } else { \$hours = \$hours; \$min = '00'; } }

• Wyrm (unregistered) in reply to Wyrm

(Ah, my bad, the "else if" blocks are misplaced.)

• Chris (unregistered)

I assumed at first glance that this was part of some code to advance some time value. That is, the check for if (\$hours == 12) was meant to then set \$hours = 1, else \$hours = \$hours + 1. Although, I would assume such code would be part of a larger if (\$min == 59), \$min = 0... [do above], else \$min = \$min + 1. Perhaps it once said all that, then they worked out that they could just use some built-in functions to handle adding one minute to a time value, and "updated" the code to not add anything, instead of removing it entirely. Still a serious WTF if that's the case.

• (nodebb) in reply to I Am The Very Model

Yes it is. In fact, formatting is the second-most important thing.

The first one is a good sarcasm detector.

• HK-47 (unregistered) in reply to Brian Boorman

The worst part are the people formatting if as if it were a function by placing opening brace on the next line and leaving out space between keyword and opening parentheses.

That must be the most brainless way of formatting if blocks.

• Al (unregistered) in reply to HK-47

I actually find 'then' and 'endif' much nicer to read code. Verbose FTW!

• Guest (unregistered) in reply to Brian Boorman

Lol? I smell sarcasm :)