Use different timezone depending on url with Rails

In my project, I've different " locale " : en, fr, ... We can see it in the URL as localhost:3000/ \locale\ /......

I search gem or methods to make a relation between this locate and timezone. In fact, I don't want to use OS timezone but timezone depending on my URL.

I specify that I'm french and a new developer on Rails.

Thanks you for your future answer.

Jon Skeet
people
quotationmark

Locales generally don't have enough information to specify the time zone. For example:

  • en just means "English" - is that in the US? The UK? Canada? Australia? Somewhere else?
  • Even with a bit more specification, it doesn't pin it down enough: en-US covers the whole of the US, which has multiple time zones
  • While you could have a locale ID with a "variant" specifying the location more specifically, that would be very unusual, and at that point you're going pretty non-standard.

Additionally, just because a user wants to see content formatted according to a particular locale, that doesn't mean they necessarily want to use that time zone. For example, I might be in France (and using the Paris time zone) but still want the page rendered in English. What would your URL do then?

(As an aside, usually the locale would be inferred from headers or URL parameters rather than as part of the URL path...)

You haven't told us anything about the project, but I would suggest trying to keep different concepts separate from each other.

people

See more on this question at Stackoverflow