We have a application which is built on PHP. In the application we have given an option to select their appropriate timezone and for every timezone we’ve stored relevant php timezone identifier (as specified here) in the database.
Now we are migrating all the backend processes related to that application to Ruby but the problem we are facing right now is how to deal with the timezone as they are stored in php format. How to use them in ruby ? Is there are library/gem which can convert php timezone format to ruby ? is there a similar way as php like date_default_timezone_set ?
As Andrew suggested the best option is really to completely get rid of the PHP time zones if possible. The next best thing would be to create a mapping from PHP zones to something like
ActiveSupportzone names.You could use this to help you with the mapping:
http://api.rubyonrails.org/classes/ActiveSupport/TimeZone.html
For those mappings that do not direcly match up between PHP and
ActiveSupport::TimeZoneyou have to manually create the mapping. However there are not that many zones in the PHP spec to begin with, so proper mapping should not be too much work.EDIT
You can include
ActiveSupportseparately into any Ruby application. You can even install the gem separately (gem install activesupport). You do not require a Rails application to be able to use it.However if you want to use something similar, but not Rails related, you can take a look at the
TZInfolibrary:http://tzinfo.rubyforge.org/
http://tzinfo.rubyforge.org/doc/
There is no standard solution to convert between PHP time zones and Ruby zones. If you’re migrating towards Ruby, then start converting everything to
TZInfo-type data.