X-Git-Url: https://git.llucax.com/mecon/meconlib.git/blobdiff_plain/2fd178ea6def247c049e517ceed19519034935bb..c0cc0ddabd54d39b68079ef97f414b799211aa67:/lib/MECON/Tiempo/Hora.php?ds=sidebyside diff --git a/lib/MECON/Tiempo/Hora.php b/lib/MECON/Tiempo/Hora.php index 347f08e..4da62ff 100644 --- a/lib/MECON/Tiempo/Hora.php +++ b/lib/MECON/Tiempo/Hora.php @@ -36,64 +36,54 @@ require_once 'Date/Span.php'; */ class MECON_Tiempo_Hora extends Date_Span { - function set - ($str) { + function set($str) + { $str = strval($str); if (preg_match('/^\d+$/', $str)) { if ($str < 24) { $str = sprintf('0:%02d:00:00', $str ); - } - elseif ($str == 24 or $str == 2400) { + } elseif ($str == 24 or $str == 2400) { $str = '1:00:00:00'; - } - elseif ($str < 2400) { + } elseif ($str < 2400) { switch (strlen($str)) { - case 2: + case 2: $str = sprintf('0:%02d:%02d:00', $str{0}, $str{1}); - break; - case 3: - $str = sprintf('0:%02d:%02d:00', $str{0}, $str{1} . $str{2}); - break; - case 4: - $str = sprintf('0:%02d:%02d:00', $str{0} . $str{1}, $str{2} . $str{3}); - break; + break; + case 3: + $str = sprintf('0:%02d:%02d:00', $str{0}, $str{1} . $str{2}); + break; + case 4: + $str = sprintf('0:%02d:%02d:00', $str{0} . $str{1}, $str{2} . $str{3}); + break; } - } - else { + } else { return false; } - } - elseif (preg_match('/^(\d{0,2})\D(\d{1,2})$/', $str, $m)) { + } elseif (preg_match('/^(\d{0,2})\D(\d{1,2})$/', $str, $m)) { if ($m[1] < 24 and $m[2] < 60) { $str = sprintf('0:%02d:%02d:00', $m[1], $m[2]); - } - elseif ($m[1] == 24 and $m[2] == 0) { + } elseif ($m[1] == 24 and $m[2] == 0) { $str = '1:00:00:00'; - } - else { + } else { return false; } - } - elseif (preg_match('/^(\d{0,2})\D(\d{1,2})\D(\d{1,2})$/', $str, $m)) { + } elseif (preg_match('/^(\d{0,2})\D(\d{1,2})\D(\d{1,2})$/', $str, $m)) { if ($m[1] < 24 and $m[2] < 60 and $m[3] < 60) { $str = sprintf('0:%02d:%02d:%02d', $m[1], $m[2], $m[3]); - } - elseif ($m[1] == 24 and $m[2] == 0 and $m[3] == 0) { + } elseif ($m[1] == 24 and $m[2] == 0 and $m[3] == 0) { $str = '1:00:00:00'; - } - else { + } else { return false; } - } - else { + } else { return false; } $this->setFromString($str, "%D:%H:%M:%S"); return true; } - function get - () { + function get() + { return $this->format("%E:%M"); }