Article 3YM4Y CodeSOD: Padding Your Time

CodeSOD: Padding Your Time

by
Remy Porter
from The Daily WTF on (#3YM4Y)

Today will be a simple one, and it's arguably low-hanging fruit, because once again, it's date handling code. But it's not handling dates where it falls down. It falls down on something much more advanced: conditionals. Supplied by "_ek1n".

if ($min == 0) { if ($hours == 12) { $hours = 12; $min = '00'; } else { $hours = $hours; $min = '00'; }}

My favorite part is the type-conversion/padding: turning 0 into '00', especially the fact that the same padding doesn't happen if $min is 1, or 3, or anything else less than 10. Or, it probably does happen, and it probably happens in a general fashion which would also pad out the 0- or maybe it doesn't, and TRWTF is that their padding method can't zero-pad a zero.

The most likely situation, though, is that this is just a brain fart.

otter-icon.png [Advertisement] Otter - Provision your servers automatically without ever needing to log-in to a command prompt. Get started today! TheDailyWtf?d=yIl2AUoC8zAo9qgBxsJRPE
External Content
Source RSS or Atom Feed
Feed Location http://syndication.thedailywtf.com/TheDailyWtf
Feed Title The Daily WTF
Feed Link http://thedailywtf.com/
Reply 0 comments