Created
August 11, 2014 16:15
-
-
Save radbasa/a46169551a671f238198 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// ..... | |
elseif ( preg_match( '/(time|timestamp)/', $type ) ) | |
{ | |
if ( preg_match( '/([0-2]?[0-9]\:[0-5][0-9])/', $value ) ) | |
{ | |
// if time entered is in the form of a simple string | |
// hh:mm | |
$timesplit = preg_split( '/\:/', $value ); | |
$hour = $timesplit[ 0 ]; | |
$minute = $timesplit[ 1 ]; | |
if ( ( $hour > 0 && $hour < 24 ) && ( $minute > 0 && $minute < 60 ) ) | |
{ | |
$valid = true; | |
} | |
else | |
{ | |
$this->_Error = 751; | |
$this->_ErrorText[] = 'Data at row ' . $i . 'col ' . $j . 'is not a valid time. ' . $this->_Error; | |
} | |
} | |
elseif ( preg_match( '/(0\.[0-9]+)/', $value ) ) | |
{ | |
// excel provides cells in time format as fraction of a day | |
// 1.00 = 24 hours | |
$valid = true; | |
$value *= 24; | |
$timesplit = preg_split( '/\./', $value ); | |
$hour = $timesplit[ 0 ]; | |
$minute = $timesplit[ 1 ]; | |
$minute = '.' . $minute; | |
$minute *= 60; | |
$minute = round( $minute ); | |
$value = $hour . ':' . $minute; | |
} | |
else | |
{ | |
$this->_Error = 752; | |
$this->_ErrorText[] = 'Data at row ' . $i . 'col ' . $j . ' does not have the correct time format. ' . $this->_Error; | |
} | |
} | |
//.... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment