Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add iana timezone database support to js-joda #32

Closed
pithu opened this issue Mar 22, 2016 · 16 comments
Closed

Add iana timezone database support to js-joda #32

pithu opened this issue Mar 22, 2016 · 16 comments
Assignees
Milestone

Comments

@pithu
Copy link
Member

@pithu pithu commented Mar 22, 2016

This issue is the place to discuss and plan the feature "iana tz db support" for js-joda.

The iana Time Zone Database contains data that represent the history of local time around the globe and is coordinated by the Internet Assigned Numbers Authority (IANA). The latest version of the database is provided at https://www.iana.org/time-zones.

js-joda already implements the core class for zone based date time values, ZonedDateTime, but with support for fixed zone offsets and the system default zone only. Not yet ported is the code for daylight saving transitions, compiling, compressing and providing the zone rules.

It might be not necessary to port the threeten code for compiling and compressing the tz db but instead use parts of the code of the moment timezone project http://momentjs.com/timezone/.

@pithu pithu changed the title add iana timezone database support to js-joda Add iana timezone database support to js-joda Mar 22, 2016
@pithu pithu added this to the M2 milestone Mar 22, 2016
@pithu pithu self-assigned this Mar 29, 2016
@Turbo87
Copy link

@Turbo87 Turbo87 commented Jun 1, 2016

@pithu has there been any progress on this issue so far?

@pithu
Copy link
Member Author

@pithu pithu commented Jun 2, 2016

Beside a "proof of concept", unfortunately no. It is not to much to do, but i did not find the time.

Mainly this things are still missing

  • Migrate the missing threeten code and tests for correct handling of daylight saving transitions (mainly in the ZonedDateTime class)
  • Introduce a new "js-joda iana tzdb module"
    -- Implement a ZoneRulesProvider
    -- Find a way to wrap the existing moment-timezone tzdb. Probably with the es6 version of moment-timezone
    -- Implement a "Guess ZoneRegion from an Instant and ZoneOffset". This is required because the Javascript spec to not provide a System default ZoneRegion.

A colleague of mine came up with a proof of concept for wrapping the moment timezone code. He reports that it works fine for his case, but of course, it is just a quick hack. find the code in the this gist https://gist.github.com/pithu/23128485d022af27a5b36b3fbbf6d92e

@maggiepint
Copy link

@maggiepint maggiepint commented Jun 2, 2016

Just FYI - you might want to look at moment/moment#3134. This is Tim cleaning up the way moment timezone does timezone adjustments in the moment core library. We haven't decided for sure to move forward on this because a lot of libraries depend on moment and there's some concern about breakage. I think we will though, as it really helps the code. Inherently, if you could support this same interface, you might be able to run moment-timezone right on top of what you have. I haven't thought very hard about this for your use case though, so I could be totally wrong.
Let me know if you need help grocking it. I can try to walk you through, or send Tim over. Also, I can't speak to whether Tim wants to officially support other libraries using this change, but in general he's usually pretty open to being helpful, as you know.

@pithu
Copy link
Member Author

@pithu pithu commented Jun 7, 2016

Hello @maggiepint, thank you for your answer.

My idea of implementing js-joda iana tzdb is to implement it conform to the threeten API and just use a small part from moment-timezone: the packed data json file containing the iana tzdb and the code to unpack it. So in opposite to code of the gist above, we will depend only very little to moment-timezone.

As soon as we have some more concrete ideas, it would be great to discuss it with you and to match it with your future plans.

@pithu
Copy link
Member Author

@pithu pithu commented Oct 6, 2016

By releasing js-joda@v1.1.12 we made the next step towards timezone support. 1.1.12 implement/ complete/ fixes the handling of daylight transition edge case. The ZoneProvider and the iana tzdb are still missing

@DanielSWolf
Copy link

@DanielSWolf DanielSWolf commented Nov 14, 2016

Given that IANA support is still pending, I assume that there is currently no way to parse a string like this: 2011-12-03T10:15:30+01:00[Europe/Paris] including the named time zone. (This format is supported by java.time).

Is that correct? -- If so, do you have a timeframe when this feature will be available?

@pithu
Copy link
Member Author

@pithu pithu commented Nov 16, 2016

Hello @DanielSWolf

yes, correct, parsing of ZoneRegions as supplied in iana tzdb is currently not working.

We are currently about to refine our plugin/ module separation logic and i pushed a first very early version of https://github.com/js-joda/js-joda-timezone today, just containing a stub.

After implementing the the two moment adapter classes (provider and rules) at js-joda-timezone, zone-id calculation should work out of the box, eg. localDateTime.atZone(ZoneId.of('Europe/Berlin')). So we are not to far away from a first beta version.

But unfortunately i cant promise you any timeframe

@pithu
Copy link
Member Author

@pithu pithu commented Nov 16, 2016

@pithu
Copy link
Member Author

@pithu pithu commented Dec 22, 2016

We recently published a pre-release of js-joda-timezone@0.0.5, together with the latest js-joda release the most common timezone functionality of the core library is working quite well, like parsing and converting to other timezones.

const zone = ZoneId.of('Europe/Berlin')

let zdt = LocalDateTime.parse('2016-06-30T11:30').atZone(zone) // 2016-06-30T11:30+02:00[Europe/Berlin]
zdt = ZonedDateTime.parse('2016-06-30T11:30+02:00[Europe/Berlin]')     // 2016-06-30T11:30+02:00[Europe/Berlin]
zdt.withZoneSameInstant(ZoneId.of('America/New_York')) // 2016-06-30T05:30-04:00[America/New_York]
zdt.withZoneSameLocal(ZoneId.of('America/New_York'))   // 2016-06-30T11:30-04:00[America/New_York]

But there are still known issues, like calculations during gap/ overlap of a daylight transition might be incorrect, test coverage is low and there is some space for performance optimization.

@jrnail23
Copy link

@jrnail23 jrnail23 commented Jan 26, 2017

According to the Roadmap section of the README.md in this repo, this is already achieved as of v1.2. Is that documentation incorrect, or is the v1.2 implementation safe for production use?

@pithu
Copy link
Member Author

@pithu pithu commented Jan 27, 2017

Hello @jrnail23, thx for using js-joda.

Yes, js-joda v1.2 is production ready.

But for iana tzdb support you need the zone rule provider https://github.com/js-joda/js-joda-timezone, the package has a pre-release version only, with some minor issues (see Readme.md). It should work for the most use cases, just when converting a LocalDateTime in a daylight saving gap/ overlap transition, it might add the offset in the wrong direction.

The issues are easy to fix and i will release a production ready version of js-joda-timezone in a couple of weeks.

@pithu
Copy link
Member Author

@pithu pithu commented Feb 4, 2017

Mission complete!!!

We just released js-joda-timezone@1.0.0 that provides full iana tzdb support for js-joda@1.3.

🍾 🍾 🍾 🍾 🍾

@phueper
Copy link
Member

@phueper phueper commented Feb 4, 2017

👍👏

@pithu pithu closed this Feb 4, 2017
@mj1856
Copy link

@mj1856 mj1856 commented Feb 4, 2017

Congrats! The Moment team also applauds your efforts. 👍

@cressie176
Copy link

@cressie176 cressie176 commented Feb 4, 2017

Great stuff. Really appreciate the effort. 👍

@pithu
Copy link
Member Author

@pithu pithu commented Feb 5, 2017

Thanks for the flowers and thanks to the moment team for providing the compact json format of the timezone information's. It saves us a lot of time.

btw: js-joda-time just depends on the moment json files and the packed format. We copied the code for unpacking from the moment-timezone es6 branch. @maggiepint do you know if there are any plans to change the format in the future?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
8 participants
You can’t perform that action at this time.