I am using tsjzt: http://pellepim.bitbucket.org/jstz/ on the client side to capture the time zone of the current users, which I store in my user object.
It works great and gives me time like Europe / London. I want to check when it will be passed to the model that it is a valid time zone if something bad happens.
So, I found this question: Report a custom timezone check for a Rails application on Heroku and tried this check:
validates_inclusion_of :timezone, :in => { in: ActiveSupport::TimeZone.zones_map(&:name) }
However, the name is different from tzinfo. I think that my client side discovered the time line "Europe / London", in fact, is a component of the value of the TimeZone display in the TimeZone class, and not the name, which in this case will be set to "London".
So, I tried this:
validates_inclusion_of :timezone, :in => { in: ActiveSupport::TimeZone.zones_map(&:tzinfo) }
None of the original answers to another SO question or mine modified from :tzinfo work, as they both fail to check when: the time zone is βEurope / Londonβ, when, obviously, it is a valid time zone!
What am I doing wrong with this time zone check and how to fix it?
ruby datetime validation ruby-on-rails ruby-on-rails-4
RenegadeAndy
source share