move static access to datetime parse function

main
msquare 8 years ago
parent eec10ebfc5
commit 42144ed21c

@ -69,15 +69,15 @@ function shift_edit_controller() {
$msg .= error(_('Please select a shifttype.'), true); $msg .= error(_('Please select a shifttype.'), true);
} }
if (isset($_REQUEST['start']) && $tmp = DateTime::createFromFormat("Y-m-d H:i", trim($_REQUEST['start']))) { if (isset($_REQUEST['start']) && $tmp = parse_date("Y-m-d H:i", $_REQUEST['start'])) {
$start = $tmp->getTimestamp(); $start = $tmp;
} else { } else {
$valid = false; $valid = false;
$msg .= error(_("Please enter a valid starting time for the shifts."), true); $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']))) { if (isset($_REQUEST['end']) && $tmp = parse_date("Y-m-d H:i", $_REQUEST['end'])) {
$end = $tmp->getTimestamp(); $end = $tmp;
} else { } else {
$valid = false; $valid = false;
$msg .= error(_("Please enter a valid ending time for the shifts."), true); $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' }); 'event-id' });
$shifts_pb[$event_id] = [ $shifts_pb[$event_id] = [
'shifttype_id' => $shifttype_id, 'shifttype_id' => $shifttype_id,
'start' => DateTime::createFromFormat("Ymd\THis", $event->dtstart)->getTimestamp() - $add_minutes_start * 60, 'start' => parse_date("Ymd\THis", $event->dtstart) - $add_minutes_start * 60,
'end' => DateTime::createFromFormat("Ymd\THis", $event->dtend)->getTimestamp() + $add_minutes_end * 60, 'end' => parse_date("Ymd\THis", $event->dtend) + $add_minutes_end * 60,
'RID' => $rooms_import[trim($event->location)], 'RID' => $rooms_import[trim($event->location)],
'title' => trim($event->summary), 'title' => trim($event->summary),
'URL' => trim($event->url), 'URL' => trim($event->url),

@ -9,7 +9,7 @@ function admin_shifts() {
$valid = true; $valid = true;
$rid = 0; $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; $end = $start;
$mode = 'single'; $mode = 'single';
$angelmode = 'manually'; $angelmode = 'manually';
@ -71,15 +71,15 @@ function admin_shifts() {
error(_('Please select a location.')); error(_('Please select a location.'));
} }
if (isset($_REQUEST['start']) && $tmp = DateTime::createFromFormat("Y-m-d H:i", trim($_REQUEST['start']))) { if (isset($_REQUEST['start']) && $tmp = parse_date("Y-m-d H:i", $_REQUEST['start'])) {
$start = $tmp->getTimestamp(); $start = $tmp;
} else { } else {
$valid = false; $valid = false;
error(_('Please select a start time.')); error(_('Please select a start time.'));
} }
if (isset($_REQUEST['end']) && $tmp = DateTime::createFromFormat("Y-m-d H:i", trim($_REQUEST['end']))) { if (isset($_REQUEST['end']) && $tmp = parse_date("Y-m-d H:i", $_REQUEST['end'])) {
$end = $tmp->getTimestamp(); $end = $tmp;
} else { } else {
$valid = false; $valid = false;
error(_('Please select an end time.')); error(_('Please select an end time.'));
@ -188,7 +188,7 @@ function admin_shifts() {
} while ($shift_end < $end); } while ($shift_end < $end);
} elseif ($mode == 'variable') { } elseif ($mode == 'variable') {
rsort($change_hours); 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; $change_index = 0;
// Ersten/nächsten passenden Schichtwechsel suchen // Ersten/nächsten passenden Schichtwechsel suchen
foreach ($change_hours as $i => $change_hour) { foreach ($change_hours as $i => $change_hour) {
@ -205,7 +205,7 @@ function admin_shifts() {
$shift_start = $start; $shift_start = $start;
do { 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; $shift_end = $day + $change_hours[$change_index] * 60 * 60;
if ($shift_end > $end) { 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); $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']))) { if (isset($_REQUEST['planned_arrival_date']) && $tmp = parse_date("Y-m-d", $_REQUEST['planned_arrival_date'])) {
$planned_arrival_date = DateTime::createFromFormat("Y-m-d", trim($_REQUEST['planned_arrival_date']))->getTimestamp(); $planned_arrival_date = $tmp;
} else { } else {
$valid = false; $valid = false;
$msg .= error(_("Please enter your planned date of arrival."), true); $msg .= error(_("Please enter your planned date of arrival."), true);

@ -56,16 +56,16 @@ function user_settings() {
$valid = false; $valid = false;
} }
if (isset($_REQUEST['planned_arrival_date']) && DateTime::createFromFormat("Y-m-d", trim($_REQUEST['planned_arrival_date']))) { if (isset($_REQUEST['planned_arrival_date']) && $tmp = parse_date("Y-m-d", $_REQUEST['planned_arrival_date'])) {
$planned_arrival_date = DateTime::createFromFormat("Y-m-d", trim($_REQUEST['planned_arrival_date']))->getTimestamp(); $planned_arrival_date = $tmp;
} else { } else {
$valid = false; $valid = false;
$msg .= error(_("Please enter your planned date of arrival."), true); $msg .= error(_("Please enter your planned date of arrival."), true);
} }
if (isset($_REQUEST['planned_departure_date']) && $_REQUEST['planned_departure_date'] != '') { if (isset($_REQUEST['planned_departure_date']) && $_REQUEST['planned_departure_date'] != '') {
if (DateTime::createFromFormat("Y-m-d", trim($_REQUEST['planned_departure_date']))) { if ($tmp = parse_date("Y-m-d", $_REQUEST['planned_departure_date'])) {
$planned_departure_date = DateTime::createFromFormat("Y-m-d", trim($_REQUEST['planned_departure_date']))->getTimestamp(); $planned_departure_date = $tmp;
} else { } else {
$valid = false; $valid = false;
$msg .= error(_("Please enter your planned date of departure."), true); $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"; $end_time = "23:59";
} }
$startdatetime = DateTime::createFromFormat("Y-m-d H:i", $start_day . " " . $start_time); $shiftsFilter->setStartTime(parse_date("Y-m-d H:i", $start_day . " " . $start_time));
$shiftsFilter->setStartTime($startdatetime->getTimestamp()); $shiftsFilter->setEndTime(parse_date("Y-m-d H:i", $end_day . " " . $end_time));
$enddatetime = DateTime::createFromFormat("Y-m-d H:i", $end_day . " " . $end_time);
$shiftsFilter->setEndTime($enddatetime->getTimestamp());
} }
return $shiftsFilter; return $shiftsFilter;

@ -1,5 +1,26 @@
<?php <?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. * Leitet den Browser an die übergebene URL weiter und hält das Script an.
*/ */
@ -11,7 +32,8 @@ function redirect($url) {
/** /**
* Echoes given output and dies. * Echoes given output and dies.
* *
* @param String $output * @param String $output
* String to display
*/ */
function raw_output($output) { function raw_output($output) {
echo $output; echo $output;
@ -20,7 +42,7 @@ function raw_output($output) {
/** /**
* Helper function for transforming list of entities into array for select boxes. * Helper function for transforming list of entities into array for select boxes.
* *
* @param array $data * @param array $data
* The data array * The data array
* @param string $key_name * @param string $key_name
@ -81,8 +103,8 @@ function check_request_date($name, $error_message = null, $null_allowed = false)
* @return ValidationResult containing the parsed date * @return ValidationResult containing the parsed date
*/ */
function check_date($input, $error_message = null, $null_allowed = false) { function check_date($input, $error_message = null, $null_allowed = false) {
if (DateTime::createFromFormat("Y-m-d", trim($input))) { if ($tmp = parse_date("Y-m-d", trim($input))) {
return new ValidationResult(true, DateTime::createFromFormat("Y-m-d", trim($input))->getTimestamp()); return new ValidationResult(true, $tmp);
} }
if ($null_allowed) { if ($null_allowed) {
return new ValidationResult(true, null); return new ValidationResult(true, null);

Loading…
Cancel
Save