I have a timestamp field in a model where the time is stored in UTC. I would like like to create a 'virtual' property that allows me to access the model using local time based on the timezone property also stored in the model. That is when I get the local_started_at property it reads the started_at property and adjusts the value based on the timezone property.
What is the cleanest way to go about this?
function doit()
{
bob = ORM::factory('user')->where('name', '=', 'bob')->find();
bob->timezone = 'Vancouver/America';
bob->local_started_at = '2010-08-11 08:00:00';
bob->save();
echo bob->started_at;
}
Output would be the UTC time for 8am Vancouver time (3 PM UTC).
2010-08-11 15:00:00
The main purpose will be to take input from a form that allows users to work in local times.
My attempt at overloading __get and __set does not appear to be working.