What's new

Welcome to xCrud Community - Data Management and extended PHP CRUD

Join us now to get access to all our features. Once registered and logged in, you will be able to create topics, post replies to existing threads, give reputation to your fellow members, get your own private messenger, and so, so much more. It's also quick and totally free, so what are you waiting for?

Beware funny timezone issues (solution)

ben74

New member
Joined
Dec 13, 2021
Messages
20
Reaction score
5
Points
3
Location
France
Hello guys,

After once again scratching my head I found again some funny things inside xcrud:

in xcrud.php, at the top, you'll see the default timezone set to:

Code:
date_default_timezone_set('Africa/Nairobi');

I really don't know what was the idea with this but it messed up tons of functions in my code.

So to solve this I just reset it to UTC:

Code:
date_default_timezone_set('UTC');

And then I've created a callback function that I use to modify mysql's UTC date to match whatever my timezone is.

example callback function:


Code:
function display_correct_paris_time($value, $fieldname, $primary_key, $row, $xcrud_leads){
    $correct_date_time =  new DateTime($value, new DateTimeZone('UTC'));
    $correct_date_time->setTimezone(new DateTimeZone('Europe/Paris'));
    return $correct_date_time->format('Y-m-d H:i:s');
}

simply called like that:

Code:
$xcrud->column_callback('created_on', 'display_correct_paris_time');
$xcrud->field_callback('created_on', 'display_correct_paris_time');

Hope it'll help if you get the same kind of funky behavior!
 
Top Bottom