Kimai_Format::check_time_format PHP Method

check_time_format() public static method

Check if a parset string matches with the following time-formatting: 20.08.2008-19:00:00.
public static check_time_format ( string $timestring ) : boolean
$timestring string
return boolean
    public static function check_time_format($timestring)
    {
        if (!preg_match("/([0-9]{1,2})\\.([0-9]{1,2})\\.([0-9]{2,4})-([0-9]{1,2}):([0-9]{1,2}):([0-9]{1,2})/", $timestring)) {
            return false;
            // WRONG format
        }
        $ok = 1;
        $hours = substr($timestring, 11, 2);
        $minutes = substr($timestring, 14, 2);
        $seconds = substr($timestring, 17, 2);
        if ((int) $hours >= 24) {
            $ok = 0;
        }
        if ((int) $minutes >= 60) {
            $ok = 0;
        }
        if ((int) $seconds >= 60) {
            $ok = 0;
        }
        Kimai_Logger::logfile("timecheck: " . $ok);
        $day = substr($timestring, 0, 2);
        $month = substr($timestring, 3, 2);
        $year = substr($timestring, 6, 4);
        if (!checkdate((int) $month, (int) $day, (int) $year)) {
            $ok = 0;
        }
        Kimai_Logger::logfile("time/datecheck: " . $ok);
        if ($ok) {
            return true;
        }
        return false;
    }

Usage Example

コード例 #1
0
ファイル: processor.php プロジェクト: kimai/kimai
 $data['designation'] = $_REQUEST['designation'];
 $data['comment'] = isset($_REQUEST['comment']) && !empty($_REQUEST['comment']) ? $_REQUEST['comment'] : '';
 $data['commentType'] = $_REQUEST['commentType'];
 $data['refundable'] = getRequestBool('refundable');
 $data['multiplier'] = getRequestDecimal($_REQUEST['multiplier']);
 $data['value'] = getRequestDecimal($_REQUEST['edit_value']);
 $data['userID'] = $kga['user']['userID'];
 if (!is_numeric($data['multiplier']) || $data['multiplier'] <= 0) {
     $errors['multiplier'] = $kga['lang']['errorMessages']['multiplierNegative'];
 }
 // parse new day and time
 $edit_day = Kimai_Format::expand_date_shortcut($_REQUEST['edit_day']);
 $edit_time = Kimai_Format::expand_time_shortcut($_REQUEST['edit_time']);
 // validate day and time
 $new = "{$edit_day}-{$edit_time}";
 if (!Kimai_Format::check_time_format($new)) {
     $errors[''] = $kga['lang']['TimeDateInputError'];
 }
 // convert to internal time format
 $new_time = convert_time_strings($new, $new);
 $data['timestamp'] = $new_time['in'];
 expenseAccessAllowed($data, $action, $errors);
 if (count($errors) > 0) {
     echo json_encode(array('errors' => $errors));
     break;
 }
 $result = false;
 if ($id) {
     if (expense_edit($id, $data) === false) {
         $errors[''] = $kga['lang']['error'];
     }