mirror of
https://github.com/tc39/test262.git
synced 2025-07-28 08:24:23 +02:00
Temporal: Add tests for toLocaleString with no options
For each Temporal object, add tests for what components are present by default if no options for date or time components are passed.
This commit is contained in:
parent
9e6ab9bb02
commit
573234fe7b
@ -0,0 +1,24 @@
|
|||||||
|
// Copyright (C) 2024 Igalia, S.L. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
esid: sec-temporal.instant.prototype.tolocalestring
|
||||||
|
description: Tests what information is present by default
|
||||||
|
locale: [en]
|
||||||
|
features: [Temporal]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
const instant = new Temporal.Instant(1735213600_321_000_000n); // 2024-12-26T11:46:40.321Z
|
||||||
|
const result = instant.toLocaleString("en", { timeZone: "UTC" });
|
||||||
|
|
||||||
|
assert(result.includes("2024"), `Instant formatted with no options ${result} should include year`);
|
||||||
|
assert(result.includes("12") || result.includes("Dec"), `Instant formatted with no options ${result} should include month`);
|
||||||
|
assert(result.includes("26"), `Instant formatted with no options ${result} should include day`);
|
||||||
|
assert(result.includes("11"), `Instant formatted with no options ${result} should include hour`);
|
||||||
|
assert(result.includes("46"), `Instant formatted with no options ${result} should include minute`);
|
||||||
|
assert(result.includes("40"), `Instant formatted with no options ${result} should include second`);
|
||||||
|
assert(!result.includes("321"), `Instant formatted with no options ${result} should not include fractional second digits`);
|
||||||
|
assert(
|
||||||
|
!result.includes("UTC") && !result.includes("Coordinated Universal Time"),
|
||||||
|
`Instant formatted with no options ${result} should not include time zone name`
|
||||||
|
);
|
@ -0,0 +1,21 @@
|
|||||||
|
// Copyright (C) 2024 Igalia, S.L. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
esid: sec-temporal.plaindate.prototype.tolocalestring
|
||||||
|
description: Tests what information is present by default
|
||||||
|
locale: [en]
|
||||||
|
features: [Temporal]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
const plainDate = new Temporal.PlainDate(2024, 12, 26);
|
||||||
|
const result = plainDate.toLocaleString("en", { timeZone: "UTC" });
|
||||||
|
|
||||||
|
assert(result.includes("2024"), `PlainDate formatted with no options ${result} should include year`);
|
||||||
|
assert(result.includes("12") || result.includes("Dec"), `PlainDate formatted with no options ${result} should include month`);
|
||||||
|
assert(result.includes("26"), `PlainDate formatted with no options ${result} should include day`);
|
||||||
|
assert(!result.includes("00"), `PlainDate formatted with no options ${result} should not include hour, minute, second`);
|
||||||
|
assert(
|
||||||
|
!result.includes("UTC") && !result.includes("Coordinated Universal Time"),
|
||||||
|
`PlainDate formatted with no options ${result} should not include time zone name`
|
||||||
|
);
|
@ -0,0 +1,24 @@
|
|||||||
|
// Copyright (C) 2024 Igalia, S.L. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
esid: sec-temporal.plaindatetime.prototype.tolocalestring
|
||||||
|
description: Tests what information is present by default
|
||||||
|
locale: [en]
|
||||||
|
features: [Temporal]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
const plainDateTime = new Temporal.PlainDateTime(2024, 12, 26, 11, 46, 40, 321);
|
||||||
|
const result = plainDateTime.toLocaleString("en", { timeZone: "UTC" });
|
||||||
|
|
||||||
|
assert(result.includes("2024"), `PlainDateTime formatted with no options ${result} should include year`);
|
||||||
|
assert(result.includes("12") || result.includes("Dec"), `PlainDateTime formatted with no options ${result} should include month`);
|
||||||
|
assert(result.includes("26"), `PlainDateTime formatted with no options ${result} should include day`);
|
||||||
|
assert(result.includes("11"), `PlainDateTime formatted with no options ${result} should include hour`);
|
||||||
|
assert(result.includes("46"), `PlainDateTime formatted with no options ${result} should include minute`);
|
||||||
|
assert(result.includes("40"), `PlainDateTime formatted with no options ${result} should include second`);
|
||||||
|
assert(!result.includes("321"), `PlainDateTime formatted with no options ${result} should not include fractional second digits`);
|
||||||
|
assert(
|
||||||
|
!result.includes("UTC") && !result.includes("Coordinated Universal Time"),
|
||||||
|
`PlainDateTime formatted with no options ${result} should not include time zone name`
|
||||||
|
);
|
@ -0,0 +1,21 @@
|
|||||||
|
// Copyright (C) 2024 Igalia, S.L. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
esid: sec-temporal.plainmonthday.prototype.tolocalestring
|
||||||
|
description: Tests what information is present by default
|
||||||
|
locale: [en-u-ca-iso8601]
|
||||||
|
features: [Temporal]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
const plainMonthDay = new Temporal.PlainMonthDay(12, 26);
|
||||||
|
const result = plainMonthDay.toLocaleString("en-u-ca-iso8601", { timeZone: "UTC" });
|
||||||
|
|
||||||
|
assert(!result.includes("1972"), `PlainMonthDay formatted with no options ${result} should not include reference year`);
|
||||||
|
assert(result.includes("12") || result.includes("Dec"), `PlainMonthDay formatted with no options ${result} should include month`);
|
||||||
|
assert(result.includes("26"), `PlainMonthDay formatted with no options ${result} should include day`);
|
||||||
|
assert(!result.includes("00"), `PlainMonthDay formatted with no options ${result} should not include hour, minute, second`);
|
||||||
|
assert(
|
||||||
|
!result.includes("UTC") && !result.includes("Coordinated Universal Time"),
|
||||||
|
`PlainMonthDay formatted with no options ${result} should not include time zone name`
|
||||||
|
);
|
@ -0,0 +1,23 @@
|
|||||||
|
// Copyright (C) 2024 Igalia, S.L. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
esid: sec-temporal.plaintime.prototype.tolocalestring
|
||||||
|
description: Tests what information is present by default
|
||||||
|
locale: [en]
|
||||||
|
features: [Temporal]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
const plainTime = new Temporal.PlainTime(11, 46, 40, 321);
|
||||||
|
const result = plainTime.toLocaleString("en", { timeZone: "UTC" });
|
||||||
|
|
||||||
|
assert(!result.includes("1970"), `PlainTime formatted with no options ${result} should not include year`);
|
||||||
|
assert(!result.includes("01") && !result.includes("Jan"), `PlainTime formatted with no options ${result} should not include month or day`);
|
||||||
|
assert(result.includes("11"), `PlainTime formatted with no options ${result} should include hour`);
|
||||||
|
assert(result.includes("46"), `PlainTime formatted with no options ${result} should include minute`);
|
||||||
|
assert(result.includes("40"), `PlainTime formatted with no options ${result} should include second`);
|
||||||
|
assert(!result.includes("321"), `PlainTime formatted with no options ${result} should not include fractional second digits`);
|
||||||
|
assert(
|
||||||
|
!result.includes("UTC") && !result.includes("Coordinated Universal Time"),
|
||||||
|
`PlainTime formatted with no options ${result} should not include time zone name`
|
||||||
|
);
|
@ -0,0 +1,21 @@
|
|||||||
|
// Copyright (C) 2024 Igalia, S.L. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
esid: sec-temporal.plainyearmonth.prototype.tolocalestring
|
||||||
|
description: Tests what information is present by default
|
||||||
|
locale: [en-u-ca-iso8601]
|
||||||
|
features: [Temporal]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
const plainYearMonth = new Temporal.PlainYearMonth(2024, 12, "iso8601", 26); // nonstandard reference day
|
||||||
|
const result = plainYearMonth.toLocaleString("en-u-ca-iso8601", { timeZone: "UTC" });
|
||||||
|
|
||||||
|
assert(result.includes("2024"), `PlainYearMonth formatted with no options ${result} should include year`);
|
||||||
|
assert(result.includes("12") || result.includes("Dec"), `PlainYearMonth formatted with no options ${result} should include month`);
|
||||||
|
assert(!result.includes("26"), `PlainYearMonth formatted with no options ${result} should not include reference day`);
|
||||||
|
assert(!result.includes("00"), `PlainYearMonth formatted with no options ${result} should not include hour, minute, second`);
|
||||||
|
assert(
|
||||||
|
!result.includes("UTC") && !result.includes("Coordinated Universal Time"),
|
||||||
|
`PlainYearMonth formatted with no options ${result} should not include time zone name`
|
||||||
|
);
|
@ -0,0 +1,24 @@
|
|||||||
|
// Copyright (C) 2024 Igalia, S.L. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
esid: sec-temporal.zoneddatetime.prototype.tolocalestring
|
||||||
|
description: Tests what information is present by default
|
||||||
|
locale: [en]
|
||||||
|
features: [Temporal]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
const zonedDateTime = new Temporal.ZonedDateTime(1735213600_321_000_000n, "UTC"); // 2024-12-26T11:46:40.321Z
|
||||||
|
const result = zonedDateTime.toLocaleString("en");
|
||||||
|
|
||||||
|
assert(result.includes("2024"), `ZonedDateTime formatted with no options ${result} should include year`);
|
||||||
|
assert(result.includes("12") || result.includes("Dec"), `ZonedDateTime formatted with no options ${result} should include month`);
|
||||||
|
assert(result.includes("26"), `ZonedDateTime formatted with no options ${result} should include day`);
|
||||||
|
assert(result.includes("11"), `ZonedDateTime formatted with no options ${result} should include hour`);
|
||||||
|
assert(result.includes("46"), `ZonedDateTime formatted with no options ${result} should include minute`);
|
||||||
|
assert(result.includes("40"), `ZonedDateTime formatted with no options ${result} should include second`);
|
||||||
|
assert(!result.includes("321"), `ZonedDateTime formatted with no options ${result} should not include fractional second digits`);
|
||||||
|
assert(
|
||||||
|
result.includes("UTC") || result.includes("Coordinated Universal Time"),
|
||||||
|
`ZonedDateTime formatted with no options ${result} should include time zone name`
|
||||||
|
);
|
Loading…
x
Reference in New Issue
Block a user