mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-28 06:08:52 +00:00
[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
This commit is contained in:
parent
1716e2a2a5
commit
3e3489195f
1 changed files with 15 additions and 0 deletions
|
@ -647,6 +647,21 @@ class phpbb_user extends phpbb_session
|
||||||
return new phpbb_datetime($time, $timezone, $this);
|
return new phpbb_datetime($time, $timezone, $this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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
|
* Get language id currently used by the user
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Add table
Reference in a new issue