globalizejs / globalize

A JavaScript library for internationalization and localization that leverages the official Unicode CLDR JSON data
https://globalizejs.com
MIT License
4.8k stars 603 forks source link

Date: Olson-timezone-support (real 'z', 'v', 'V') and options.timeZone #701

Closed rxaviers closed 7 years ago

rxaviers commented 7 years ago

Checklist:

Notes:

rxaviers commented 7 years ago

The below is wrong, it should use "British Summer Time" name instead.

Globalize('en-GB').formatDate(new Date(2017,8,1), {datetime: 'full', timeZone: 'Europe/London'})
'Friday, 1 September 2017 at 04:00:00 GMT+01:00'

Edit: this has been fixed.

jsf-clabot commented 7 years ago

CLA assistant check
All committers have signed the CLA.

rxaviers commented 7 years ago

To quickly demo what's coming... I hope you like it!

npm install globalize@1.3.0-alpha.0 cldr-data iana-tz-data
var Globalize = require( "globalize" );
Globalize.load( require( "cldr-data" ).entireSupplemental() );
Globalize.load( require( "cldr-data" ).entireMainFor( "en" ) );
Globalize.loadIANATimezone( require( "iana-tz-data" ) );

Globalize( "en" ).formatDate(new Date(), {datetime: "short", timeZone: "America/Los_Angeles"});
// > '3/19/17, 3:19 PM'
Globalize( "en" ).formatDate(new Date(), {datetime: "short", timeZone: "America/New_York"});
// > '3/19/17, 6:19 PM'
Globalize( "en" ).formatDate(new Date(), {datetime: "short", timeZone: "America/Sao_Paulo"});
// > '3/19/17, 7:19 PM'
Globalize( "en" ).formatDate(new Date(), {datetime: "short", timeZone: "Europe/Berlin"});
// > '3/19/17, 11:19 PM'

Globalize( "en" ).formatDate(new Date(), {datetime: "full", timeZone: "America/Los_Angeles"});
// > 'Sunday, March 19, 2017 at 3:19:22 PM Pacific Daylight Time'
Globalize( "en" ).formatDate(new Date(), {datetime: "full", timeZone: "America/New_York"});
// > 'Sunday, March 19, 2017 at 6:19:22 PM Eastern Daylight Time'
Globalize( "en" ).formatDate(new Date(), {datetime: "full", timeZone: "America/Sao_Paulo"});
// > 'Sunday, March 19, 2017 at 7:19:22 PM Brasilia Standard Time'
Globalize( "en" ).formatDate(new Date(), {datetime: "full", timeZone: "Europe/Berlin"});
// > 'Sunday, March 19, 2017 at 11:19:53 PM Central European Standard Time'
mattyork commented 7 years ago

@rxaviers I LOVE YOU. We need this.

mattyork commented 7 years ago

Any updates on this? We need to add support for timezones in the next few weeks.

mattyork commented 7 years ago

Globalize compiler isn't working with the alpha. Versions used:

    "globalize": "1.3.0-alpha.3",
    "globalize-compiler": "0.3.0-alpha.3",
    "iana-tz-data": "2017.1.0",

Here's the script that's failing:

const ianaTzData = require('iana-tz-data');
const Globalize = require("globalize");
const cldrData = require('./vendor/cldr-data.json');
Globalize.loadIANATimeZone(ianaTzData);
Globalize.load(cldrData);
Globalize.locale("en");

const date = new Date();
const d1 = Globalize.dateFormatter({ datetime: "full" })
console.log(d1(date))

const globalizeCompiler = require('globalize-compiler');

const out = globalizeCompiler.compile([d1])

It fails here in the globalize compiler, failing to extract the formatter because it doesn't have the runtimeArgs. image

rxaviers commented 7 years ago

Hi @mattyork, we should have a 1.3.0 soon.

About the issue above, Thanks for reporting it.

rxaviers commented 7 years ago

For the record, the fix for the dateFormatter runtime issue is here: #724

rxaviers commented 7 years ago

Rebased and squashed

rxaviers commented 7 years ago

Merged :man_dancing: