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