-
Notifications
You must be signed in to change notification settings - Fork 241
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
EZP-29279: Values of Date Field Type should be handled in UTC only (#…
…1401) * EZP-29279: ezdate timestamps are now stored in UTC * Added missing hours, minutes and seconds to Timestamp conversion and add more s p a c e s to the same class code * Fixup after CR
- Loading branch information
1 parent
215ce2c
commit 3ce2994
Showing
3 changed files
with
57 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?php | ||
/** | ||
* File containing the eZTimestamp class. | ||
* | ||
* @copyright Copyright (C) eZ Systems AS. All rights reserved. | ||
* @license For full copyright and license information view LICENSE file distributed with this source code. | ||
* @version //autogentag// | ||
* @package lib | ||
*/ | ||
|
||
class eZTimestamp | ||
{ | ||
/*! | ||
\return a timestamp in UTC | ||
*/ | ||
public static function getUtcTimestampFromLocalTimestamp( $localTimestamp ) { | ||
$utcTimezone = new \DateTimeZone( 'UTC' ); | ||
$localTimezone = new \DateTimeZone( date_default_timezone_get() ); | ||
|
||
$localDate = new \DateTime( null, $localTimezone ); | ||
$localDate->setTimestamp( $localTimestamp ); | ||
$utcDate = new \DateTime( $localDate->format( 'Y-m-d H:i:s' ), $utcTimezone ); | ||
|
||
return $utcDate->getTimestamp(); | ||
} | ||
|
||
/*! | ||
\return a timestamp in timezone defined in php.ini | ||
*/ | ||
public static function getLocalTimestampFromUtcTimestamp( $utcTimestamp ) { | ||
$utcTimezone = new \DateTimeZone( 'UTC' ); | ||
$localTimezone = new \DateTimeZone( date_default_timezone_get() ); | ||
|
||
$utcDate = new \DateTime( null, $utcTimezone ); | ||
$utcDate->setTimestamp( $utcTimestamp ); | ||
$localDate = new \DateTime( $utcDate->format( 'Y-m-d H:i:s' ), $localTimezone ); | ||
|
||
return $localDate->getTimestamp(); | ||
} | ||
} | ||
?> |