summaryrefslogtreecommitdiff
path: root/includes/sys_page.php
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/sys_page.php
parenteec10ebfc5c14ab9b72d3b81b7d44a2e507f5473 (diff)
move static access to datetime parse function
Diffstat (limited to 'includes/sys_page.php')
-rw-r--r--includes/sys_page.php30
1 files changed, 26 insertions, 4 deletions
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);