We use PHP built-in methods to handle time difference.
Saving
To convert user input data (that is of course in his timezone):
Base_RegionalSettingsCommon::reg2time:
1. save server timezone
2. set server timezone to user timezone
3. obtain unix timestamp from the date using strtotime - unix timestamp is always in UTC
4. restore server timezone saved in 1.
Then, when it's saved in the database by RecordBrowser:
1. call date('Y-m-d H:i:s', $unix_timestamp)
It's called with default server timezone and it's formatted according to this timezone.
Reading
1. Obtain data from database (which is in format 'Y-m-d H:i:s')
2. Base_RegionalSettingsCommon::time2reg($time) formats output with strftime method. You can supply unixtimestamp of formatted date to time2reg.
formatted date will be converted to unix timestamp with strtotime (it will be adjusted according to the server default timezone)
Example
I'll be operating on numbers, not timezone names
Saving:
Your timezone is UTC+8 (somewhere in Russia?). It's 20:00.
Your server is UTC-6 (somewhere in the USA).
Creating a meeting:
Input: 16:45
UTC: 8:45 (of course in seconds since Unix epoch)
Server: 2:45
In database: 2:45
Reading for your friend that is UTC+2 (Eastern Europe)
Database: 2:45
UTC: 8:45
Output: 10:45
Utils_RecordBrowserCommon::get_record doesn't adjust any fields values.
use Utils_RecordBrowserCommon::get_val('crm_meeting', $time_field, $record); to get user timezone time
to convert database value to UTC time:
$val = get_database_value(); // it's in server timezone and in format 2013-10-14 12:29:30
$unix_ts = strtotime($val);
date_default_timezone_set('UTC');
$utc_val = date('Y-m-d H:i:s', $unix_tx);
Thanks for this question. I've realized that every date in EPESI may be shifted if you'll change the server default timezone. e.g. migrate your EPESI to different server. And that there is a hidden setting SYSTEM_TIMEZONE in config.php where you can set the old timezone setting 🙂
Regards,
Adam