summaryrefslogtreecommitdiff
path: root/includes
diff options
context:
space:
mode:
authormsquare <msquare@notrademark.de>2016-10-04 17:58:56 +0200
committermsquare <msquare@notrademark.de>2016-10-04 17:58:56 +0200
commit42144ed21cbc7361857b375d719ec53b24314546 (patch)
treeea8c80aa429e6bc1009a1372c3e4ddddf086932a /includes
parenteec10ebfc5c14ab9b72d3b81b7d44a2e507f5473 (diff)
move static access to datetime parse function
Diffstat (limited to 'includes')
-rw-r--r--includes/controller/shifts_controller.php8
-rw-r--r--includes/pages/admin_import.php4
-rw-r--r--includes/pages/admin_shifts.php14
-rw-r--r--includes/pages/guest_login.php4
-rw-r--r--includes/pages/user_settings.php8
-rw-r--r--includes/pages/user_shifts.php7
-rw-r--r--includes/sys_page.php30
7 files changed, 47 insertions, 28 deletions
diff --git a/includes/controller/shifts_controller.php b/includes/controller/shifts_controller.php
index 3300c0d2..ca6fd906 100644
--- a/includes/controller/shifts_controller.php
+++ b/includes/controller/shifts_controller.php
@@ -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);
diff --git a/includes/pages/admin_import.php b/includes/pages/admin_import.php
index 2c36e681..4af09dca 100644
--- a/includes/pages/admin_import.php
+++ b/includes/pages/admin_import.php
@@ -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),
diff --git a/includes/pages/admin_shifts.php b/includes/pages/admin_shifts.php
index 3dd22f3a..42a8c682 100644
--- a/includes/pages/admin_shifts.php
+++ b/includes/pages/admin_shifts.php
@@ -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) {
diff --git a/includes/pages/guest_login.php b/includes/pages/guest_login.php
index 1f1b7ab2..9f688321 100644
--- a/includes/pages/guest_login.php
+++ b/includes/pages/guest_login.php
@@ -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);
diff --git a/includes/pages/user_settings.php b/includes/pages/user_settings.php
index b2ea5752..22ead68b 100644
--- a/includes/pages/user_settings.php
+++ b/includes/pages/user_settings.php
@@ -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);
diff --git a/includes/pages/user_shifts.php b/includes/pages/user_shifts.php
index ad211181..8b6dd1fc 100644
--- a/includes/pages/user_shifts.php
+++ b/includes/pages/user_shifts.php
@@ -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;
diff --git a/includes/sys_page.php b/includes/sys_page.php
index e62909ab..f20a791c 100644
--- a/includes/sys_page.php
+++ b/includes/sys_page.php
@@ -1,6 +1,27 @@
<?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.
*/
function redirect($url) {
@@ -11,7 +32,8 @@ function redirect($url) {
/**
* Echoes given output and dies.
*
- * @param String $output
+ * @param String $output
+ * String to display
*/
function raw_output($output) {
echo $output;
@@ -20,7 +42,7 @@ function raw_output($output) {
/**
* Helper function for transforming list of entities into array for select boxes.
- *
+ *
* @param array $data
* The data array
* @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
*/
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);