Kimai_Format::expand_time_shortcut PHP Method

expand_time_shortcut() public static method

Allowed shortcut formats are shown in the dialogue for edit timesheet entries (click the "?").
public static expand_time_shortcut ( $time ) : string
return string
    public static function expand_time_shortcut($time)
    {
        $time = str_replace(" ", "", $time);
        // empty string can't be a time value
        if (strlen($time) == 0) {
            return false;
        }
        // get the parts
        $parts = preg_split("/:|\\./", $time);
        for ($i = 0; $i < count($parts); $i++) {
            switch (strlen($parts[$i])) {
                case 0:
                    return false;
                case 1:
                    $parts[$i] = "0" . $parts[$i];
            }
        }
        // fill unsued parts (eg. 12:00 given but 12:00:00 is needed)
        while (count($parts) < 3) {
            $parts[] = "00";
        }
        $return = implode(":", $parts);
        $regex23 = '([0-1][0-9])|(2[0-3])';
        // regular expression for hours
        $regex59 = '([0-5][0-9])';
        // regular expression for minutes and seconds
        if (!preg_match("/^({$regex23}):({$regex59}):({$regex59})\$/", $return)) {
            $return = false;
        }
        return $return;
    }

Usage Example

コード例 #1
0
ファイル: processor.php プロジェクト: kimai/kimai
 }
 // get new data
 $data['projectID'] = $_REQUEST['projectID'];
 $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) {