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

dateFormatter with raw pattern isn't handling two single quotes correctly when outside quoted text #822

Open jonathan-saunders-ge opened 6 years ago

jonathan-saunders-ge commented 6 years ago

Thanks for this great package! :-)

The LDML spec says: "Two adjacent single vertical quotes (''), which represent a literal single quote, either inside or outside quoted text."

However globalize.dateFormatter({raw: "h''m''s''"}) returns "456" instead of "4'5'6'".

I ran this over at https://npm.runkit.com/globalize

var Globalize = require("globalize")
Globalize.load( require( "cldr-data" ).entireSupplemental() );
Globalize.load( require( "cldr-data" ).entireMainFor( "en" ) );
Globalize.loadTimeZone( require( "iana-tz-data" ) );
var globalize = Globalize( "en" ),
    date = new Date( 2001, 2-1, 3, 4, 5, 6, 789 );
var check = function (fmt) {
    console.log(fmt + '    ==>    ' + globalize.dateFormatter({raw: fmt})(date));
};
check("h''m''s''"); // fails, expect 4'5'6' but get 456
check("'h''m''s'''"); // works, expect h'm's'
check("h''''m''''s"); // fails, expect 4'5'6 (or 4''5''6, unclear from spec?) but get 456
rxaviers commented 6 years ago

Thank you for reporting this bug, yeap this should work as you say