eZ Publish  [4.0]
ezdatetimevalidator.php
Go to the documentation of this file.
00001 <?php
00002 //
00003 // Definition of eZDateTimeValidator class
00004 //
00005 //
00006 // ## BEGIN COPYRIGHT, LICENSE AND WARRANTY NOTICE ##
00007 // SOFTWARE NAME: eZ Publish
00008 // SOFTWARE RELEASE: 4.0.x
00009 // COPYRIGHT NOTICE: Copyright (C) 1999-2008 eZ Systems AS
00010 // SOFTWARE LICENSE: GNU General Public License v2.0
00011 // NOTICE: >
00012 //   This program is free software; you can redistribute it and/or
00013 //   modify it under the terms of version 2.0  of the GNU General
00014 //   Public License as published by the Free Software Foundation.
00015 //
00016 //   This program is distributed in the hope that it will be useful,
00017 //   but WITHOUT ANY WARRANTY; without even the implied warranty of
00018 //   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00019 //   GNU General Public License for more details.
00020 //
00021 //   You should have received a copy of version 2.0 of the GNU General
00022 //   Public License along with this program; if not, write to the Free
00023 //   Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
00024 //   MA 02110-1301, USA.
00025 //
00026 //
00027 // ## END COPYRIGHT, LICENSE AND WARRANTY NOTICE ##
00028 //
00029 
00030 /*! \file ezdatetimevalidator.php
00031 */
00032 
00033 /*!
00034   \class eZDateTimeValidator ezdatetimevalidator.php
00035   \brief The class eZDateTimeValidator does
00036 
00037 */
00038 
00039 //include_once( 'lib/ezutils/classes/ezinputvalidator.php' );
00040 
00041 class eZDateTimeValidator extends eZInputValidator
00042 {
00043     /*!
00044      Constructor
00045     */
00046     function eZDateTimeValidator()
00047     {
00048     }
00049 
00050     static function validateDate( $day, $month, $year )
00051     {
00052         $check = checkdate( $month, $day, $year );
00053         $datetime = mktime( 0, 0, 0, $month, $day, $year );
00054         if ( !$check or
00055              $year < 1970 or
00056              $datetime === false )
00057         {
00058             return eZInputValidator::STATE_INVALID;
00059         }
00060         return eZInputValidator::STATE_ACCEPTED;
00061     }
00062 
00063     static function validateTime( $hour, $minute )
00064     {
00065         if( preg_match( '/\d+/', trim( $hour )   ) &&
00066             preg_match( '/\d+/', trim( $minute ) ) &&
00067             $hour >= 0 && $minute >= 0 &&
00068             $hour < 24 && $minute < 60 )
00069         {
00070             return eZInputValidator::STATE_ACCEPTED;
00071         }
00072         return eZInputValidator::STATE_INVALID;
00073     }
00074 
00075     static function validateDateTime( $day, $month, $year, $hour, $minute )
00076     {
00077         $check = checkdate( $month, $day, $year );
00078         $datetime = mktime( $hour, $minute, 0, $month, $day, $year );
00079         if ( !$check or
00080              $year < 1970 or
00081              $datetime === false or
00082              eZDateTimeValidator::validateTime( $hour, $minute ) == eZInputValidator::STATE_INVALID )
00083         {
00084             return eZInputValidator::STATE_INVALID;
00085         }
00086         return eZInputValidator::STATE_ACCEPTED;
00087     }
00088 
00089     /// \privatesection
00090 }
00091 
00092 ?>