1

Supposing I have

  • a date (i.e. an UTC timestamp),
  • a location (e.g. "Paris") that I may encode as I wish (and which isn't the one of the browser),
  • no permanent internet access

then what can I do if I want to format my date for this specific location, correctly dealing with daylight saving time when/if it occurs ? I'd prefer a standard based solution. I expect the solution to either include a reliable table of some sorts or to call some browser/computer magic.

Of course, as the offset is dependent of the moment, I can't just store the location as an offset.

Here are 2 points which ease the problem :

  • I won't deal with dates before 2010
  • if some country decides to change the rules regarding its timezone, it's acceptable for me to release a new code/library
Denys Séguret
  • 372,613
  • 87
  • 782
  • 758
  • EDIT : right now I'm looking at https://github.com/mde/timezone-js but this is a huge js... – Denys Séguret Aug 05 '13 at 11:42
  • See also: [other timezone libraries for javascript](http://stackoverflow.com/a/15171030/634824). Also - are you talking about any city in the world from arbitrary text? Or are you choosing a time zone from a list? – Matt Johnson-Pint Aug 05 '13 at 15:28
  • @MattJohnson thanks for that link (you got a +1). I have a fixed, maintained, list of locations. In fact I went for a totally different solution leveraging the fact that one of the servers in my system already has the Olson tables and can send the needed info but moment.js solution with the ability to extract custom timezone info is fine too. – Denys Séguret Aug 05 '13 at 15:35
  • Either sounds like a good approach. It gets more challenging if you don't have fixed locations that you can assign Olson zones to. Then you have to use [geolocation by lat/lon coordinates](http://stackoverflow.com/q/16086962/634824). – Matt Johnson-Pint Aug 05 '13 at 16:32

1 Answers1

1

Have a look at moment.js which support localization in a pretty nice way as well as time zones.

For the location issue, I would say you will have a really hard time solving that without an Internet connection. I would say the only way to solve it is to have your users enter a country (and maybe time zone) manually.

Mikael Östberg
  • 16,982
  • 6
  • 61
  • 79