move static access to datetime parse function
This commit is contained in:
parent
eec10ebfc5
commit
42144ed21c
|
@ -69,15 +69,15 @@ function shift_edit_controller() {
|
|||
$msg .= error(_('Please select a shifttype.'), true);
|
||||
}
|
||||
|
||||
if (isset($_REQUEST['start']) && $tmp = DateTime::createFromFormat("Y-m-d H:i", trim($_REQUEST['start']))) {
|
||||
$start = $tmp->getTimestamp();
|
||||
if (isset($_REQUEST['start']) && $tmp = parse_date("Y-m-d H:i", $_REQUEST['start'])) {
|
||||
$start = $tmp;
|
||||
} else {
|
||||
$valid = false;
|
||||
$msg .= error(_("Please enter a valid starting time for the shifts."), true);
|
||||
}
|
||||
|
||||
if (isset($_REQUEST['end']) && $tmp = DateTime::createFromFormat("Y-m-d H:i", trim($_REQUEST['end']))) {
|
||||
$end = $tmp->getTimestamp();
|
||||
if (isset($_REQUEST['end']) && $tmp = parse_date("Y-m-d H:i", $_REQUEST['end'])) {
|
||||
$end = $tmp;
|
||||
} else {
|
||||
$valid = false;
|
||||
$msg .= error(_("Please enter a valid ending time for the shifts."), true);
|
||||
|
|
|
@ -312,8 +312,8 @@ function prepare_events($file, $shifttype_id, $add_minutes_start, $add_minutes_e
|
|||
'event-id' });
|
||||
$shifts_pb[$event_id] = [
|
||||
'shifttype_id' => $shifttype_id,
|
||||
'start' => DateTime::createFromFormat("Ymd\THis", $event->dtstart)->getTimestamp() - $add_minutes_start * 60,
|
||||
'end' => DateTime::createFromFormat("Ymd\THis", $event->dtend)->getTimestamp() + $add_minutes_end * 60,
|
||||
'start' => parse_date("Ymd\THis", $event->dtstart) - $add_minutes_start * 60,
|
||||
'end' => parse_date("Ymd\THis", $event->dtend) + $add_minutes_end * 60,
|
||||
'RID' => $rooms_import[trim($event->location)],
|
||||
'title' => trim($event->summary),
|
||||
'URL' => trim($event->url),
|
||||
|
|
|
@ -9,7 +9,7 @@ function admin_shifts() {
|
|||
$valid = true;
|
||||
|
||||
$rid = 0;
|
||||
$start = DateTime::createFromFormat("Y-m-d H:i", date("Y-m-d") . " 00:00")->getTimestamp();
|
||||
$start = parse_date("Y-m-d H:i", date("Y-m-d") . " 00:00");
|
||||
$end = $start;
|
||||
$mode = 'single';
|
||||
$angelmode = 'manually';
|
||||
|
@ -71,15 +71,15 @@ function admin_shifts() {
|
|||
error(_('Please select a location.'));
|
||||
}
|
||||
|
||||
if (isset($_REQUEST['start']) && $tmp = DateTime::createFromFormat("Y-m-d H:i", trim($_REQUEST['start']))) {
|
||||
$start = $tmp->getTimestamp();
|
||||
if (isset($_REQUEST['start']) && $tmp = parse_date("Y-m-d H:i", $_REQUEST['start'])) {
|
||||
$start = $tmp;
|
||||
} else {
|
||||
$valid = false;
|
||||
error(_('Please select a start time.'));
|
||||
}
|
||||
|
||||
if (isset($_REQUEST['end']) && $tmp = DateTime::createFromFormat("Y-m-d H:i", trim($_REQUEST['end']))) {
|
||||
$end = $tmp->getTimestamp();
|
||||
if (isset($_REQUEST['end']) && $tmp = parse_date("Y-m-d H:i", $_REQUEST['end'])) {
|
||||
$end = $tmp;
|
||||
} else {
|
||||
$valid = false;
|
||||
error(_('Please select an end time.'));
|
||||
|
@ -188,7 +188,7 @@ function admin_shifts() {
|
|||
} while ($shift_end < $end);
|
||||
} elseif ($mode == 'variable') {
|
||||
rsort($change_hours);
|
||||
$day = DateTime::createFromFormat("Y-m-d H:i", date("Y-m-d", $start) . " 00:00")->getTimestamp();
|
||||
$day = parse_date("Y-m-d H:i", date("Y-m-d", $start) . " 00:00");
|
||||
$change_index = 0;
|
||||
// Ersten/nächsten passenden Schichtwechsel suchen
|
||||
foreach ($change_hours as $i => $change_hour) {
|
||||
|
@ -205,7 +205,7 @@ function admin_shifts() {
|
|||
|
||||
$shift_start = $start;
|
||||
do {
|
||||
$day = DateTime::createFromFormat("Y-m-d H:i", date("Y-m-d", $shift_start) . " 00:00")->getTimestamp();
|
||||
$day = parse_date("Y-m-d H:i", date("Y-m-d", $shift_start) . " 00:00");
|
||||
$shift_end = $day + $change_hours[$change_index] * 60 * 60;
|
||||
|
||||
if ($shift_end > $end) {
|
||||
|
|
|
@ -104,8 +104,8 @@ function guest_register() {
|
|||
$msg .= error(sprintf(_("Your password is too short (please use at least %s characters)."), MIN_PASSWORD_LENGTH), true);
|
||||
}
|
||||
|
||||
if (isset($_REQUEST['planned_arrival_date']) && DateTime::createFromFormat("Y-m-d", trim($_REQUEST['planned_arrival_date']))) {
|
||||
$planned_arrival_date = DateTime::createFromFormat("Y-m-d", trim($_REQUEST['planned_arrival_date']))->getTimestamp();
|
||||
if (isset($_REQUEST['planned_arrival_date']) && $tmp = parse_date("Y-m-d", $_REQUEST['planned_arrival_date'])) {
|
||||
$planned_arrival_date = $tmp;
|
||||
} else {
|
||||
$valid = false;
|
||||
$msg .= error(_("Please enter your planned date of arrival."), true);
|
||||
|
|
|
@ -56,16 +56,16 @@ function user_settings() {
|
|||
$valid = false;
|
||||
}
|
||||
|
||||
if (isset($_REQUEST['planned_arrival_date']) && DateTime::createFromFormat("Y-m-d", trim($_REQUEST['planned_arrival_date']))) {
|
||||
$planned_arrival_date = DateTime::createFromFormat("Y-m-d", trim($_REQUEST['planned_arrival_date']))->getTimestamp();
|
||||
if (isset($_REQUEST['planned_arrival_date']) && $tmp = parse_date("Y-m-d", $_REQUEST['planned_arrival_date'])) {
|
||||
$planned_arrival_date = $tmp;
|
||||
} else {
|
||||
$valid = false;
|
||||
$msg .= error(_("Please enter your planned date of arrival."), true);
|
||||
}
|
||||
|
||||
if (isset($_REQUEST['planned_departure_date']) && $_REQUEST['planned_departure_date'] != '') {
|
||||
if (DateTime::createFromFormat("Y-m-d", trim($_REQUEST['planned_departure_date']))) {
|
||||
$planned_departure_date = DateTime::createFromFormat("Y-m-d", trim($_REQUEST['planned_departure_date']))->getTimestamp();
|
||||
if ($tmp = parse_date("Y-m-d", $_REQUEST['planned_departure_date'])) {
|
||||
$planned_departure_date = $tmp;
|
||||
} else {
|
||||
$valid = false;
|
||||
$msg .= error(_("Please enter your planned date of departure."), true);
|
||||
|
|
|
@ -75,11 +75,8 @@ function update_ShiftsFilter(ShiftsFilter $shiftsFilter, $user_shifts_admin, $da
|
|||
$end_time = "23:59";
|
||||
}
|
||||
|
||||
$startdatetime = DateTime::createFromFormat("Y-m-d H:i", $start_day . " " . $start_time);
|
||||
$shiftsFilter->setStartTime($startdatetime->getTimestamp());
|
||||
|
||||
$enddatetime = DateTime::createFromFormat("Y-m-d H:i", $end_day . " " . $end_time);
|
||||
$shiftsFilter->setEndTime($enddatetime->getTimestamp());
|
||||
$shiftsFilter->setStartTime(parse_date("Y-m-d H:i", $start_day . " " . $start_time));
|
||||
$shiftsFilter->setEndTime(parse_date("Y-m-d H:i", $end_day . " " . $end_time));
|
||||
}
|
||||
|
||||
return $shiftsFilter;
|
||||
|
|
|
@ -1,5 +1,26 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* Provide page/request helper functions
|
||||
*/
|
||||
|
||||
/**
|
||||
* Parse a date into unix timestamp
|
||||
*
|
||||
* @param string $pattern
|
||||
* The date pattern (i.e. Y-m-d H:i)
|
||||
* @param string $value
|
||||
* The string to parse
|
||||
* @return The parsed unix timestamp
|
||||
*/
|
||||
function parse_date($pattern, $value) {
|
||||
$datetime = DateTime::createFromFormat($pattern, trim($value));
|
||||
if ($datetime == null) {
|
||||
return null;
|
||||
}
|
||||
return $datetime->getTimestamp();
|
||||
}
|
||||
|
||||
/**
|
||||
* Leitet den Browser an die übergebene URL weiter und hält das Script an.
|
||||
*/
|
||||
|
@ -12,6 +33,7 @@ function redirect($url) {
|
|||
* Echoes given output and dies.
|
||||
*
|
||||
* @param String $output
|
||||
* String to display
|
||||
*/
|
||||
function raw_output($output) {
|
||||
echo $output;
|
||||
|
@ -81,8 +103,8 @@ function check_request_date($name, $error_message = null, $null_allowed = false)
|
|||
* @return ValidationResult containing the parsed date
|
||||
*/
|
||||
function check_date($input, $error_message = null, $null_allowed = false) {
|
||||
if (DateTime::createFromFormat("Y-m-d", trim($input))) {
|
||||
return new ValidationResult(true, DateTime::createFromFormat("Y-m-d", trim($input))->getTimestamp());
|
||||
if ($tmp = parse_date("Y-m-d", trim($input))) {
|
||||
return new ValidationResult(true, $tmp);
|
||||
}
|
||||
if ($null_allowed) {
|
||||
return new ValidationResult(true, null);
|
||||
|
|
Loading…
Reference in New Issue