Skip to content

Conversation

@catamorphism
Copy link
Contributor

@catamorphism
Copy link
Contributor Author

Awaiting tc39/proposal-temporal#3175

Copy link
Contributor

@ptomato ptomato left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

We should have similar tests for formatRange, formatToParts, formatRangeToParts, and the toLocaleString methods of PlainDate, PlainYearMonth, PlainMonthDay, PlainTime, PlainDateTime, Instant, and ZonedDateTime.

Comment on lines +15 to +16
assert(formatter.format(new Temporal.PlainYearMonth(2025, 11, "gregory")).startsWith("11"), "formatting a PlainYearMonth should work");
assert(formatter.format(new Temporal.PlainMonthDay(11, 4, "gregory")).startsWith("11"), "formatting a PlainMonthDay should work");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using "gregory" may fail depending on the calendar that formatter gets from the host's locale. Probably the best way to work around this would be to hardcode the formatter to "en", and include locales: [en] in the frontmatter.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 8ae6c62

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/locales/locale apparently. Sorry!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, it looks like the linter complains about including locales: [en] in the frontmatter? Or did I do that incorrectly?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in bd540ad

assert(formatter.format(new Temporal.PlainDate(2025, 11, 4)).startsWith("11"), "formatting a PlainDate should work");
assert(formatter.format(new Temporal.PlainYearMonth(2025, 11, "gregory")).startsWith("11"), "formatting a PlainYearMonth should work");
assert(formatter.format(new Temporal.PlainMonthDay(11, 4, "gregory")).startsWith("11"), "formatting a PlainMonthDay should work");
assert(formatter.format(new Temporal.PlainTime(14, 46)).startsWith("A"), "formatting a PlainTime should work");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a bit surprised by this expectation... It does match what comes out of new Date().toLocaleTimeString('en', { era: 'narrow' }), but my reading of the spec (GetDateTimeFormat) is that era isn't copied to formatOptions when constructing [[TemporalPlainTimeFormat]].

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed tc39/proposal-temporal#3175 (review) accordingly and updated this test.

assert(formatter.format(new Temporal.PlainMonthDay(11, 4, "gregory")).startsWith("11"), "formatting a PlainMonthDay should work");
assert(formatter.format(new Temporal.PlainTime(14, 46)).startsWith("A"), "formatting a PlainTime should work");
assert(formatter.format(new Temporal.PlainDateTime(2025, 11, 4, 14, 46)).startsWith("11"), "formatting a PlainDateTime should work");
assert(formatter.format(new Temporal.Instant(0n)).startsWith("12"), "formatting an Instant should work");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This may fail depending on the host's time zone offset. Probably the best way to work around that is pass timeZone: 'UTC' in the formatter options.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 28e653d

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess I gave you bad advice here, since the test is supposed to check what happens when you pass era with no other options.

Maybe a better approach would be to check that the output of formatter.format(new Temporal.Instant(0n)) is identical to that of new Date(0).toLocaleString(["en"], { era: "narrow" })?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants