ecma402 icon indicating copy to clipboard operation
ecma402 copied to clipboard

What does year: '18', era: '78' mean in Node 12's chinese-calendar formatToParts output?

Open justingrant opened this issue 4 years ago • 2 comments
trafficstars

@ptomato and I are running across interesting behavior for chinese/dangi calendars in Node 12 vs. Node 14. I assume it's related to #225 and/or #349? We could use some advice. Specifically:

  • What do the year and era fields refer to in Node 12 output? Is there an easy formula to convert these values to an ISO year?
  • Is there any combination of options in Node 12 to get the relatedYear in the output?

I'm asking because https://github.com/tc39/proposal-temporal/pull/1245 is adding proof-of-concept support for all ICU calendars and I'd prefer for that PR to work in Node 12 if possible. That PR depends on DateTimeFormat.formatToParts output to convert ISO dates to calendar dates and also (in a very hacky, poor-performing, not-for-production way-- but OK for proof-of-concept) for converting calendar dates to ISO.

Here's what @ptomato sees in node 12.16.1 (v8 7.8.279.23-node.31):

new Intl.DateTimeFormat('en-US-u-ca-chinese', { day: 'numeric', month: 'numeric', year: 'numeric', era: 'short', timeZone: 'UTC' }).formatToParts(new Date('2001-02-01T00:00Z'))
[
  { type: 'month', value: '1' },
  { type: 'literal', value: ' ' },
  { type: 'day', value: '9' },
  { type: 'literal', value: ', ' },
  { type: 'year', value: '18' },
  { type: 'literal', value: ' ' },
  { type: 'era', value: '78' }
]

Here's what I see in Node v14.4.0:

new Intl.DateTimeFormat('en-US-u-ca-chinese', { day: 'numeric', month: 'numeric', year: 'numeric', era: 'short', timeZone: 'UTC' }).formatToParts(new Date('2001-02-01T00:00Z'))
[
  { type: 'month', value: '1' },
  { type: 'literal', value: ' ' },
  { type: 'day', value: '9' },
  { type: 'literal', value: ', ' },
  { type: 'relatedYear', value: '2001' }
]

justingrant avatar Jan 25 '21 20:01 justingrant

@FrankYFTang

sffc avatar Jan 25 '21 20:01 sffc

not sure. I think what you saw in Node 12 is a bug.

FrankYFTang avatar Jan 26 '21 03:01 FrankYFTang