globalizejs / globalizejs/globalize

Month suffixes in dateFormatter double in japanese

Open
#764 7 comments 1 reaction 0 assignees View on GitHub
bug date module uts-35-bug
Dominant language
JavaScript
Stars
4.8k
Forks
585
PR merge metrics
No merged PRs in 30d

Description

I don't know the exact source, but here's roughly a reduced test case:

```javascript
// Setup
const Globalize = require('globalize');
Globalize.load( require( "cldr-data" ).entireSupplemental() );
Globalize.load( require( "cldr-data" ).entireMainFor('ja') );
Globalize.locale('ja-JP');

const formatterOptions = {
skeleton: 'MMMMEEEEc',
};

// Create a japanese formatter.
const f = Globalize.dateFormatter(formatterOptions);

// Format a japanese date
const japaneseDate = f.format(new Date());

// Setup en-US data
Globalize.load( require( "cldr-data" ).entireMainFor('en') );
Globalize.locale('en-US');

// Create an english formatter
const f2 = Globalize.dateFormatter(formatterOptions);
const englishDate = f2.format(newDate());

console.log(japaneseDate);
// 8月月8日(火曜日)

console.log(englishDate);
// Tuesday, August 8
```

The symbol in Japanese for `month` is `月`, so in the Japanese output we're outputting the month symbol twice.

Expected: `8月8日(火曜日)`
Actual: `8月月8日(火曜日)`

But you'll note that this is not the case for the english date (probably since there's no concept of a month symbol). I assume any locale with a month symbol would be affected by this.

In the case of Japanese, I can temporarily work around this by using `MMMMM` instead of `MMMM` (5 Ms instead of 4 Ms). Five Ms actually means 'shorthand', even though 5 > 4. In the case of Japanese, 'month' is only a single character. So the 'shorthand' is the same as the 'longhand'. So with the skeleton `MMMMMEEEEc` I actually get the expected value out. This would not work for a language with a month postfix that was not the same in long-hand and shorthand though.

It also means I have to change the skeleton based on the current locale, which defeats the purpose of the generic formatter a littler bit.

Hopefully that's a helpful starting place.

Best,
Alex

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.