In PHP I am using date_default_timezone_set
to set the default timezone.
Then whenever I use date('m/d/y g:i A')
it gives me the correct time for that timezone regardless of location of client.
However, I need to be able to set a user-defined default timezone offset when the page loads that is set in minutes. so it could be anything from -99999 to 0 to 99999.
I can't figure out how to integrate the offset with the default timezone setting.
I've seen plenty of information on how to use UTC and GMT offsets, but nothing about a custom default timezone offset (in minutes or seconds).
I'm hoping someone has some experience with this and can point me in the right direction.
Apparently this is impossible with PHP without defining a custom date wrapper and fetching and assigning the offset every time.
Does anyone else besides me think this should be included in PHP like..
date_default_timezone_set($timezone, $optionalCustomOffset);
I'm going to submit an RFC
Any help is much appreciated.
Thanks
Pet0
Well, after I test this, if it works, I think that will be equivelant to the answer I was looking for so gonna have to mark my own answer correct unless anyone gonna come forward and show me up....
(NOTE: rename and override functions require that PECL APD be installed.)
if (function_exist('__overridden__'))
{ rename_function('__overridden__', 'dummy-override'); }
rename_function('date', 'date-native');
override_function('date', '$s ="l, F jS, Y, g:i:s A", $t = null', 'return izDate($s ="l, F jS, Y, g:i:s A", $t = null);');
rename_function("__overridden__", 'date-override');
function izDate($s = 'l, F jS, Y, g:i:s A', $t = null) {
$file = ('../timezone.config');
$f = file_get_contents($file);
$offset = getTzValue($f, 'offset');
$time = $t === null ? time() : $t;
$time += $offset ? (int) $offset : 0;
return date-native($s, $time);
}
I didn't have a lot of time to wait for an answer on this one, so this is how I solved it. If anyone has a better solution or can even help me write a better wrapper for this, I will award the checkmark.
function izDate($s, $t=null) {
$file = ('../timezone.config');
$f = file_get_contents($file);
$offset = getTzValue($f, 'offset');
$time = $t===null ? time() : $t;
$time += $offset ? (int) $offset : 0;
return date($s, $time);
}