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

Get localized time zone names by time zone ID? #673

Closed
mattjohnsonpint opened this issue Jan 11, 2017 · 7 comments
Closed

Get localized time zone names by time zone ID? #673

mattjohnsonpint opened this issue Jan 11, 2017 · 7 comments

Comments

@mattjohnsonpint
Copy link

I see that the Globalize date module has some functionality that relies on timeZoneNames.json. Part of the data in these files is to support the rules defined in Part 4 Section 7 of the TR35 spec, which are used to determine the localized display name of a given time zone.

For example, given America/Los_Angeles, and en-US, I should be able to get back:

{
    "generic": "Pacific Time",
    "standard": "Pacific Standard Time",
    "daylight": "Pacific Daylight Time"
}

Is this something that Globalize can do today and I'm just not finding it in the documentation? If not, is it planned for a future release?

Thanks,
Matt

@rxaviers
Copy link
Member

rxaviers commented Jan 12, 2017

Hi @mj1856, globalize doesn't fully support timezone.

I'm closing your issue in favor of the ones above. Feel free to add comments there. Thanks

@ravalibusetty1991
Copy link

Hi, just checking again. I'm really in need of a good library in Javascript which will give me localized timezone display names. For example, "Pacific Standard Time" when I pass in "America/Los_Angeles" and "en-US". Is this supported in globalize?

@kborchers
Copy link
Contributor

I don't know if it's exactly what you need but you might want to check out some combination of Globalize, Moment Timezone and/or Spacetime.

https://momentjs.com/timezone/
https://github.com/smallwins/spacetime

@rxaviers
Copy link
Member

rxaviers commented Jun 19, 2017

​All, globalize 1.3.0 does fully support IANA/Olson time zones 😄 (currently, use globalize@1.3.0-rc.0).

@rajavelmani, see Using time zones examples here:

// Requires Globalize 1.3.0 (globalize@1.3.0-rc.0)
Globalize.loadTimeZone( require( "iana-tz-data" ) );

Globalize.locale( "en" );

Globalize.dateFormatter({ datetime: "medium", timeZone: "America/Los_Angeles" })( new Date() );
// > "Nov 1, 2010, 12:55:00 PM"

Globalize.dateFormatter({ datetime: "medium", timeZone: "America/Sao_Paulo" })( new Date() )
// > "Nov 1, 2010, 5:55:00 PM"

Globalize.dateFormatter({ datetime: "full", timeZone: "Europe/Berlin" })( new Date() )
// > "Monday, November 1, 2010 at 8:55:00 PM Central European Standard Time"

If you are only looking for displaying the time zones names only, one approach is to use this:

var fmt = Globalize.dateFormatter({ raw: "zzzz", timeZone: "America/Los_Angeles" });
fmt( new Date( 2017, 0, 1 ) ); // > 'Pacific Standard Time'
fmt( new Date( 2017, 7, 1 ) ); // > 'Pacific Daylight Time'

You can use any CLDR Zone pattern.

@rxaviers
Copy link
Member

https://momentjs.com/timezone/

Moment is a great library, but unfortunately it doesn't support CLDR. Globalize 1.3.0, which supports CLDR, now supports time zone. So basically using Globalize you have full IANA support with the strength of CLDR for i18n.

https://github.com/smallwins/spacetime

A much smaller library (0.6KB), if you need to manipulate time zone dates (no i18n), is https://github.com/rxaviers/zoned-date-time (used under the hoods by globalize).

@rxaviers
Copy link
Member

rxaviers commented Jun 19, 2017

It's worth to mention that a big concern when using time zones + i18n is the final size of your bundles...

On Globalize, you can take advantage of the Globalize Compiler. For example, let's say you are serving a content in English and for America/Los_Angeles time zone for example using this formatter:

var dateWithTimeZoneFormatter = Globalize.dateFormatter({
  datetime: "full",
  timeZone: "America/Los_Angeles"
});

The production final size of that will be:

filename minified+gzipped size
i18n/en.js (includes CLDR and IANA data) 1.7KB
core+number+date globalize runtime lib 7.0KB

See globalize compiler example or app-npm-webpack example for details.

@kborchers
Copy link
Contributor

This was all very helpful and detailed, @rxaviers. Thanks!!

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

No branches or pull requests

4 participants