tags:

views:

116

answers:

4

Hi all,

After getting an answer from this thread, it would save me alot of retyping if any readers could refer to it: link text I find that I need to update(within a mysql db) a timezone code, singularly (e.g 10+, 1-, etc) to olsen code (e.g "Europe/London", etc) according to what already exists within the user_timezone column. What would be the easiest what to go about that?

Any ideas would be very appreciated.

A: 

There is the DateTimeZone class you can work with but what you get is not the offset in hours but in minutes (IIRC).

Ólafur Waage
Hi there,I dont quite understand what you mean, sorry, I am still learning. Can you expand on what you mean alittle bit more. I have the idea that I need to do an sql query to update the database, but before so, i think i might have to pull the data first enable to compare it during the update query
Lea
It would be nice to know what data you already have and what you would like to get out of it. :D
Ólafur Waage
+1  A: 

Unfortunately you've no way of knowing which zone a user is in from the UTC offset. If you take a look at Wikipedia's list of timezones, you'll notice that many zones share the same time offset, e.g. Europe/Sarajevo and Europe/Brussels

David Caunt
Hi there, Ok. Did you BAC read that this is based on an existing database? Well, the script that created the database used the offset codes to somehow allocate a timezone to the user. I cant find it within the script though. So what are you thoughts on how they achieved this? Thanks
Lea
My guess is that they've just stored the offset for calculating local time and thrown away the specifics - the code e.g. Europe/London as they thought it wasn't useful. If the data wasn't stored then unfortunately it has gone forever. My suggestion would be to ask users on next login to specify
David Caunt
their timezone again and save the olson this time. If you explain it'll help you improve their experience or the quality of your site then I'm sure it'll be a minor inconvenience (and just a one-off!)
David Caunt
Ok, I agree. Thanks for the suggestions:)
Lea
A: 

The way to remap values in mysql looks like:

UPDATE `sometable`
SET `somecolumn` = IFNULL(ELT(FIELD(`somecolumn`,
    'oldval1', 'oldval2', 'oldval3'),
    'newval1', 'newval2', 'newval3'),
    `somecolumn`
);

That will change occurrences of 'oldval1' to 'newval1' and so on, while leaving alone anything not appearing in the 'oldval' list.

chaos
thanks for this. I will keep it for future reference.cheers!
Lea
A: 

Given that a timezone offset (e.g. UTC+2) may correspond to many entries in the Olson database (e.g. Europe/Sofia, Europe/Riga, Africa/Cairo, etc.) you have to choose beforehand the offset-to-Olson-code correspondence. Create a table describing those correspondences and then use it to build you update statement.

Milen A. Radev
Ok, this seems like the answer.Thank you:)
Lea