1 <?php /* vim: set binary expandtab tabstop=4 shiftwidth=4 textwidth=80:
2 -------------------------------------------------------------------------------
4 -------------------------------------------------------------------------------
5 This file is part of mlib.
7 mlib is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 2 of the License, or (at your option)
12 mlib is distributed in the hope that it will be useful, but WITHOUT
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14 FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License; if not,
17 write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
18 Boston, MA 02111-1307 USA
19 -------------------------------------------------------------------------------
20 Creado: lun abr 22 16:05:33 ART 2002
21 Autor: Gonzalo Merayo <gmeray@mecon.gov.ar>
22 -------------------------------------------------------------------------------
24 -----------------------------------------------------------------------------*/
26 require_once 'Date/Span.php';
29 * Representa una hora.
34 * @author Gonzalo Merayo <gmeray@mecon.gov.ar>
36 class MLIB_Tiempo_Hora extends Date_Span {
41 if (preg_match('/^\d+$/', $str)) {
43 $str = sprintf('0:%02d:00:00', $str );
44 } elseif ($str == 24 or $str == 2400) {
46 } elseif ($str < 2400) {
47 switch (strlen($str)) {
49 $str = sprintf('0:%02d:%02d:00', $str{0}, $str{1});
52 $str = sprintf('0:%02d:%02d:00', $str{0}, $str{1} . $str{2});
55 $str = sprintf('0:%02d:%02d:00', $str{0} . $str{1}, $str{2} . $str{3});
61 } elseif (preg_match('/^(\d{0,2})\D(\d{1,2})$/', $str, $m)) {
62 if ($m[1] < 24 and $m[2] < 60) {
63 $str = sprintf('0:%02d:%02d:00', $m[1], $m[2]);
64 } elseif ($m[1] == 24 and $m[2] == 0) {
69 } elseif (preg_match('/^(\d{0,2})\D(\d{1,2})\D(\d{1,2})$/', $str, $m)) {
70 if ($m[1] < 24 and $m[2] < 60 and $m[3] < 60) {
71 $str = sprintf('0:%02d:%02d:%02d', $m[1], $m[2], $m[3]);
72 } elseif ($m[1] == 24 and $m[2] == 0 and $m[3] == 0) {
80 $this->setFromString($str, "%D:%H:%M:%S");
86 return $this->format("%E:%M");