开发者

Storing a Timezone with Rails in PostgreSQL - what field type to use

开发者 https://www.devze.com 2023-03-04 18:00 出处:网络
I\'m storing timezones in my database that I get via FB\'s api. The timezone looks like: -开发者_JS百科7

I'm storing timezones in my database that I get via FB's api. The timezone looks like:

-开发者_JS百科7 

What field should I be using in rails/PostgreSQL to store this value? String?


If your timezone is always going to be an offset then use a :decimal (don't forget about places like Newfoundland Canada that are at UTC−3.5). Generally, timezones come in many different forms:

UTC-3.5
-7
America/Vancouver

So your safest bet would be a :string. The Olson Database is a good place to get an idea of the various timezone formats you'll come across.

0

精彩评论

暂无评论...
验证码 换一张
取 消