Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use NSTimeZone -timeZoneWithName: with a city name from Rails ActiveSupport?

If I only have the city name like Bangkok or Tokyo, how can I supply a timezone parameter in [NSTimeZone timeZoneWithName:@"Asia/Tokyo"] where it also has continent and slash in front of city?

I already tried [NSTimeZone timeZoneWithName:@"Tokyo"], it doesn't work.

like image 765
Hlung Avatar asked Apr 30 '12 11:04

Hlung


2 Answers

Thanks for the answers guys, but it looks like those city names are just a format that Rails "ActiveSupport::TimeZone" uses. So I just have to map it back. The mapping is here -> http://api.rubyonrails.org/classes/ActiveSupport/TimeZone.html

It maps the timezone from Rails "ActiveSupport::TimeZone" format to another format that iOS uses (e.g. "International Date Line West" => "Pacific/Midway", "Midway Island" => "Pacific/Midway", "Samoa" => "Pacific/Pago_Pago", ... ).

I have created a plist file containing a NSDictionary property that can easily be used for mapping.

Edit: an updated version (with usage example) for Rails 3.2 (thanks RJ Regenold!)

like image 143
Hlung Avatar answered Oct 17 '22 01:10

Hlung


You can see list of all timezone names.

NSLog(@"%@", [NSTimeZone knownTimeZoneNames]);

Hope this will be helpful for you.

like image 33
tagirkaZ Avatar answered Oct 16 '22 23:10

tagirkaZ