Kimai_Format::expand_date_shortcut PHP Method

expand_date_shortcut() public static method

Allowed shortcut formats are shown in the dialogue for edit timesheet entries (click the "?")
public static expand_date_shortcut ( string $date ) : string
$date string shortcut date
return string
    public static function expand_date_shortcut($date)
    {
        $date = str_replace(" ", "", $date);
        // empty string can't be a time value
        if (strlen($date) == 0) {
            return false;
        }
        // get the parts
        $parts = preg_split("/\\./", $date);
        if (count($parts) == 0 || count($parts) > 3) {
            return false;
        }
        // check day
        if (strlen($parts[0]) == 1) {
            $parts[0] = "0" . $parts[0];
        }
        // check month
        if (!isset($parts[1])) {
            $parts[1] = date("m");
        } elseif (strlen($parts[1]) == 1) {
            $parts[1] = "0" . $parts[1];
        }
        // check year
        if (!isset($parts[2])) {
            $parts[2] = date("Y");
        } elseif (strlen($parts[2]) == 2) {
            if ($parts[2] > 70) {
                $parts[2] = "19" . $parts[2];
            } else {
                if ($parts[2] < 10) {
                    $parts[2] = "200" . $parts[2];
                } else {
                    $parts[2] = "20" . $parts[2];
                }
            }
        }
        $return = implode(".", $parts);
        if (!preg_match("/([0-9]{1,2})\\.([0-9]{1,2})\\.([0-9]{2,4})/", $return)) {
            $return = false;
        }
        return $return;
    }

Usage Example

コード例 #1
0
ファイル: processor.php プロジェクト: kimai/kimai
     break;
 }
 // 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;