<?php

/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */

/**
 * Maple - PHP Web Application Framework
 *
 * PHP versions 4 and 5
 *
 * LICENSE: This source file is subject to version 3.0 of the PHP license
 * that is available through the world-wide-web at the following URI:
 * http://www.php.net/license/3_0.txt.  If you did not receive a copy of
 * the PHP License and are unable to obtain it through the web, please
 * send a note to license@php.net so we can mail you a copy immediately.
 *
 * @package     Maple.validator
 * @author      TAKAHASHI Kunihiko <kunit@kunit.jp>
 * @copyright   2004-2006 The Maple Project
 * @license     http://www.php.net/license/3_0.txt  PHP License 3.0
 * @version     CVS: $Id: Validator_Date.class.php,v 1.4 2006/02/11 19:18:22 kunit Exp $
 */


class Validator_Time extends Validator
{
    /**
     * 時刻が妥当かどうか
     *
     * @param   mixed   $attributes 時刻
     * @param   string  $errStr     エラー文字列
     * @param   array   $params     
     * @return  string  エラー文字列(エラーの場合)
     * @access  public
     * @since   3.0.0
     */
    function validate($attributes, $errStr, $params)
    {   //許可形式 00:00

        //データが5文字かどうか
        $cont = strlen($attributes);
        if($cont <> 5){
             return $errStr;
        }
        
        //「：」が含まれているかどうか
        $koron = strpbrk($attributes, ":");
        if($koron = false){
             return $errStr;
        }

        $time = explode(":", $attributes);//時間と分で分割

        //時刻部分が数値かどうか
        if(!ctype_digit($time[0]) or !ctype_digit($time[1])){
             return $errStr;
        }
        
        //時刻部分が2文字かどうか
        $hour = strlen($time[0]);
        $minutes = strlen($time[1]);
        if($hour<>2 or $minutes<>2){
             return $errStr;
        }
        
        //時間が23以下かどうか
        if($time[0] >= 24){
             return $errStr;
        }
        
        //分が59以下かどうか
        if($time[1] >= 60){
             return $errStr;
        }
        
        
    }

}
?>
