aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoas Schilling <nickvergessen@gmx.de>2012-06-18 14:32:09 +0200
committerJoas Schilling <nickvergessen@gmx.de>2012-06-18 15:11:07 +0200
commit3e3489195fb4d804e65a7a5438c33ac2fe0564b6 (patch)
treed906884db2f7298b2289a5fe1345f47326a3bde3
parent1716e2a2a57903464bf4a1b6843bca913c656695 (diff)
downloadforums-3e3489195fb4d804e65a7a5438c33ac2fe0564b6.tar
forums-3e3489195fb4d804e65a7a5438c33ac2fe0564b6.tar.gz
forums-3e3489195fb4d804e65a7a5438c33ac2fe0564b6.tar.bz2
forums-3e3489195fb4d804e65a7a5438c33ac2fe0564b6.tar.xz
forums-3e3489195fb4d804e65a7a5438c33ac2fe0564b6.zip
[feature/new-tz-handling] Add a function to get the timestamp of a date
The function uses the given timezone and returns the correct UNIX timestamp of it. PHPBB3-9558
-rw-r--r--phpBB/includes/user.php15
1 files changed, 15 insertions, 0 deletions
diff --git a/phpBB/includes/user.php b/phpBB/includes/user.php
index a36d837fbd..0990cc601a 100644
--- a/phpBB/includes/user.php
+++ b/phpBB/includes/user.php
@@ -648,6 +648,21 @@ class phpbb_user extends phpbb_session
}
/**
+ * Get the UNIX timestamp for a datetime in the users timezone, so we can store it in the database.
+ *
+ * @param string $format Format of the entered date/time
+ * @param string $time Date/time with the timezone applied
+ * @param DateTimeZone $timezone Timezone of the date/time, falls back to timezone of current user
+ * @return int Returns the unix timestamp
+ */
+ public function get_timestamp_from_format($format, $time, DateTimeZone $timezone = null)
+ {
+ $timezone = $timezone ?: $this->tz;
+ $date = DateTime::createFromFormat($format, $time, $timezone);
+ return ($date !== false) ? $date->format('U') : false;
+ }
+
+ /**
* Get language id currently used by the user
*/
function get_iso_lang_id()