Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tests for Temporal.Calendar.prototype.dayOf* #3051

Merged
merged 6 commits into from
Aug 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Copyright (C) 2021 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal.calendar.prototype.dayofweek
description: Temporal.Calendar.prototype.dayOfWeek will take Temporal.PlainDateTime objects
and return the day of week.
info: |
5. Return 𝔽(! ToISODayOfWeek(temporalDate.[[ISOYear]], temporalDate.[[ISOMonth]], temporalDate.[[ISODay]])).
features: [Temporal]
---*/
let cal = new Temporal.Calendar("iso8601");

let dt = new Temporal.PlainDateTime(1997, 1, 23, 5, 30, 13);
assert.sameValue(4, cal.dayOfWeek(dt));
dt = new Temporal.PlainDateTime(1996, 2, 23, 5, 30, 13);
assert.sameValue(5, cal.dayOfWeek(dt));
dt = new Temporal.PlainDateTime(1997, 2, 23, 5, 30, 13);
assert.sameValue(7, cal.dayOfWeek(dt));
dt = new Temporal.PlainDateTime(1997, 6, 23, 5, 30, 13);
assert.sameValue(1, cal.dayOfWeek(dt));
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Copyright (C) 2021 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal.calendar.prototype.dayofweek
description: Temporal.Calendar.prototype.dayOfWeek will take Temporal.PlainDate objects
and return the day of week.
info: |
5. Return 𝔽(! ToISODayOfWeek(temporalDate.[[ISOYear]], temporalDate.[[ISOMonth]], temporalDate.[[ISODay]])).
features: [Temporal]
---*/
let cal = new Temporal.Calendar("iso8601");

let d = new Temporal.PlainDate(1970, 1, 1);
assert.sameValue(4, cal.dayOfWeek(d));
d = new Temporal.PlainDate(2021, 2, 15);
assert.sameValue(1, cal.dayOfWeek(d));
d = new Temporal.PlainDate(2021, 8, 15);
assert.sameValue(7, cal.dayOfWeek(d));
17 changes: 17 additions & 0 deletions test/built-ins/Temporal/Calendar/prototype/dayOfWeek/string.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Copyright (C) 2021 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal.calendar.prototype.dayofweek
description: Temporal.Calendar.prototype.dayOfWeek will take ISO8601 string
and return the day of week.
info: |
4. Let temporalDate be ? ToTemporalDate(temporalDateLike).
5. Return 𝔽(! ToISODayOfWeek(temporalDate.[[ISOYear]], temporalDate.[[ISOMonth]], temporalDate.[[ISODay]])).
features: [Temporal]
---*/
let cal = new Temporal.Calendar("iso8601");

assert.sameValue(5, cal.dayOfWeek("2019-01-18"));
assert.sameValue(1, cal.dayOfWeek("2019-03-18"));
assert.sameValue(6, cal.dayOfWeek("2019-05-18"));
assert.sameValue(7, cal.dayOfWeek("2019-08-18"));
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Copyright (C) 2021 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal.calendar.prototype.dayOfWeek
description: Temporal.Calendar.prototype.dayOfWeek throws RangeError on
ToTemporalDate when temporalDateLike is invalid string.
info: |
4. Let temporalDate be ? ToTemporalDate(temporalDateLike).
features: [Temporal]
---*/
let cal = new Temporal.Calendar("iso8601");

assert.throws(RangeError, () => cal.dayOfWeek("invalid string"),
"Throw RangeError if temporalDateLike is invalid");
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Copyright (C) 2021 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal.calendar.prototype.dayOfWeek
description: Temporal.Calendar.prototype.dayOfWeek throws TypeError
when the internal lot is not presented.
info: |
2. Perform ? RequireInternalSlot(calendar, [[InitializedTemporalCalendar]]).
features: [Temporal]
---*/
let cal = new Temporal.Calendar("iso8601");

let badCal = { dayOfWeek: cal.dayOfWeek }
assert.throws(TypeError, () => badCal.dayOfWeek("2021-03-04"),
"Throw TypeError if no internal slot");
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Copyright (C) 2021 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal.calendar.prototype.dayofyear
description: Temporal.Calendar.prototype.dayOfYear will take PlainDateTime object and
return the day of year.
info: |
4. Let temporalDate be ? ToTemporalDate(temporalDateLike).
5. Return 𝔽(! ToISODayOfYear(temporalDate.[[ISOYear]], temporalDate.[[ISOMonth]], temporalDate.[[ISODay]])).
features: [Temporal]
---*/
let cal = new Temporal.Calendar("iso8601");

let dt = new Temporal.PlainDateTime(1997, 1, 23, 5, 30, 13);
assert.sameValue(23, cal.dayOfYear(dt));

dt = new Temporal.PlainDateTime(1997, 2, 23, 5, 30, 13);
assert.sameValue(54, cal.dayOfYear(dt));

dt = new Temporal.PlainDateTime(1996, 3, 23, 5, 30, 13);
assert.sameValue(83, cal.dayOfYear(dt));

dt = new Temporal.PlainDateTime(1997, 3, 23, 5, 30, 13);
assert.sameValue(82, cal.dayOfYear(dt));

dt = new Temporal.PlainDateTime(1997, 12, 31, 5, 30, 13);
assert.sameValue(365, cal.dayOfYear(dt));

dt = new Temporal.PlainDateTime(1996, 12, 31, 5, 30, 13);
assert.sameValue(366, cal.dayOfYear(dt));
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// Copyright (C) 2021 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal.calendar.prototype.dayofyear
description: Temporal.Calendar.prototype.dayOfYear will take PlainDate object and
return the day of year.
info: |
5. Return 𝔽(! ToISODayOfYear(temporalDate.[[ISOYear]], temporalDate.[[ISOMonth]], temporalDate.[[ISODay]])).
features: [Temporal]
---*/
let cal = new Temporal.Calendar("iso8601");

let d = new Temporal.PlainDate(1970, 1, 1);
assert.sameValue(1, cal.dayOfYear(d));
d = new Temporal.PlainDate(2000, 1, 1);
assert.sameValue(1, cal.dayOfYear(d));

d = new Temporal.PlainDate(2021, 1, 15);
assert.sameValue(15, cal.dayOfYear(d));

d = new Temporal.PlainDate(2020, 2, 15);
assert.sameValue(46, cal.dayOfYear(d));

d = new Temporal.PlainDate(2020, 3, 15);
assert.sameValue(75, cal.dayOfYear(d));

d = new Temporal.PlainDate(2000, 3, 15);
assert.sameValue(75, cal.dayOfYear(d));

d = new Temporal.PlainDate(2001, 3, 15);
assert.sameValue(74, cal.dayOfYear(d));

d = new Temporal.PlainDate(2000, 12, 31);
assert.sameValue(366, cal.dayOfYear(d));

d = new Temporal.PlainDate(2001, 12, 31);
assert.sameValue(365, cal.dayOfYear(d));
17 changes: 17 additions & 0 deletions test/built-ins/Temporal/Calendar/prototype/dayOfYear/string.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Copyright (C) 2021 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal.calendar.prototype.dayofyear
description: Temporal.Calendar.prototype.dayOfYear will take ISO8601 string and
return the day of year.
info: |
4. Let temporalDate be ? ToTemporalDate(temporalDateLike).
5. Return 𝔽(! ToISODayOfYear(temporalDate.[[ISOYear]], temporalDate.[[ISOMonth]], temporalDate.[[ISODay]])).
features: [Temporal]
---*/
let cal = new Temporal.Calendar("iso8601");

assert.sameValue(18, cal.dayOfYear("2019-01-18"));
assert.sameValue(49, cal.dayOfYear("2020-02-18"));
assert.sameValue(365, cal.dayOfYear("2019-12-31"));
assert.sameValue(366, cal.dayOfYear("2000-12-31"));
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Copyright (C) 2021 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal.calendar.prototype.dayOfYear
description: Temporal.Calendar.prototype.dayOfYear throws RangeError on
ToTemporalDate when temporalDateLike is invalid string.
info: |
4. Let temporalDate be ? ToTemporalDate(temporalDateLike).
features: [Temporal]
---*/
let cal = new Temporal.Calendar("iso8601");

assert.throws(RangeError, () => cal.dayOfYear("invalid string"),
"Throw RangeError if temporalDateLike is invalid");
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Copyright (C) 2021 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal.calendar.prototype.dayOfYear
description: Temporal.Calendar.prototype.dayOfYear throws TypeError
when the internal lot is not presented.
info: |
2. Perform ? RequireInternalSlot(calendar, [[InitializedTemporalCalendar]]).
features: [Temporal]
---*/
let cal = new Temporal.Calendar("iso8601");

let badCal = { dayOfYear: cal.dayOfYear }
assert.throws(TypeError, () => badCal.dayOfYear("2021-03-04"),
"Throw TypeError if no internal slot");