-
Notifications
You must be signed in to change notification settings - Fork 152
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Convert calendar arguments in SytemDateTime.
- Loading branch information
Showing
22 changed files
with
429 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// Copyright (C) 2020 Igalia, S.L. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
esid: sec-temporal.now.date | ||
---*/ | ||
|
||
const values = [ | ||
[null, "null"], | ||
[true, "true"], | ||
["iso8601", "iso8601"], | ||
[2020, "2020"], | ||
[2n, "2"], | ||
]; | ||
|
||
const calendar = Temporal.Calendar.from("iso8601"); | ||
const original = Temporal.Calendar.from; | ||
for (const [input, output] of values) { | ||
Temporal.Calendar.from = function(argument) { | ||
assert.sameValue(argument, output); | ||
// TODO: Remove. | ||
Temporal.Calendar.from = original; | ||
return calendar; | ||
}; | ||
|
||
Temporal.now.date("UTC", input); | ||
} | ||
|
||
Temporal.Calendar.from = function() { | ||
throw new Test262Error("Should not call Calendar.from"); | ||
}; | ||
|
||
assert.throws(TypeError, () => Temporal.now.date("UTC", Symbol())); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// Copyright (C) 2020 Igalia, S.L. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
esid: sec-temporal.now.date | ||
includes: [compareArray.js] | ||
---*/ | ||
|
||
const actual = []; | ||
const expected = [ | ||
"get Temporal.Calendar.from", | ||
"get timeZone.getDateTimeFor", | ||
"call timeZone.getDateTimeFor", | ||
]; | ||
const dateTime = Temporal.DateTime.from("1963-07-02T12:34:56.987654321"); | ||
|
||
const timeZone = new Proxy({ | ||
getDateTimeFor(absolute, calendar) { | ||
actual.push("call timeZone.getDateTimeFor"); | ||
assert.sameValue(absolute instanceof Temporal.Absolute, true, "Absolute"); | ||
assert.sameValue(calendar instanceof Temporal.Calendar, true, "Calendar"); | ||
assert.sameValue(calendar.id, "japanese"); | ||
return dateTime; | ||
}, | ||
}, { | ||
has(target, property) { | ||
actual.push(`has timeZone.${property}`); | ||
return property in target; | ||
}, | ||
get(target, property) { | ||
actual.push(`get timeZone.${property}`); | ||
return target[property]; | ||
}, | ||
}); | ||
|
||
Object.defineProperty(Temporal.Calendar, "from", { | ||
get() { | ||
actual.push("get Temporal.Calendar.from"); | ||
return undefined; | ||
}, | ||
}); | ||
|
||
const result = Temporal.now.date(timeZone, "japanese"); | ||
assert.sameValue(result instanceof Temporal.Date, true); | ||
for (const property of ["year", "month", "day"]) { | ||
assert.sameValue(result[property], dateTime[property], property); | ||
} | ||
|
||
assert.compareArray(actual, expected); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
// Copyright (C) 2020 Igalia, S.L. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
esid: sec-temporal.now.date | ||
includes: [compareArray.js] | ||
---*/ | ||
|
||
const actual = []; | ||
const expected = [ | ||
"get Temporal.TimeZone.from", | ||
"call Temporal.TimeZone.from", | ||
"get Temporal.Calendar.from", | ||
"call Temporal.Calendar.from", | ||
"get timeZone.getDateTimeFor", | ||
"call timeZone.getDateTimeFor", | ||
]; | ||
const dateTime = Temporal.DateTime.from("1963-07-02T12:34:56.987654321"); | ||
|
||
const calendar = {}; | ||
|
||
const timeZone = new Proxy({ | ||
getDateTimeFor(absolute, calendarArg) { | ||
actual.push("call timeZone.getDateTimeFor"); | ||
assert.sameValue(absolute instanceof Temporal.Absolute, true, "Absolute"); | ||
assert.sameValue(calendarArg, calendar); | ||
return dateTime; | ||
}, | ||
}, { | ||
has(target, property) { | ||
actual.push(`has timeZone.${property}`); | ||
return property in target; | ||
}, | ||
get(target, property) { | ||
actual.push(`get timeZone.${property}`); | ||
return target[property]; | ||
}, | ||
}); | ||
|
||
Object.defineProperty(Temporal.TimeZone, "from", { | ||
get() { | ||
actual.push("get Temporal.TimeZone.from"); | ||
return function(argument) { | ||
actual.push("call Temporal.TimeZone.from"); | ||
assert.sameValue(argument, "UTC"); | ||
return timeZone; | ||
}; | ||
}, | ||
}); | ||
|
||
Object.defineProperty(Temporal.Calendar, "from", { | ||
get() { | ||
actual.push("get Temporal.Calendar.from"); | ||
return function(argument) { | ||
actual.push("call Temporal.Calendar.from"); | ||
assert.sameValue(argument, "iso8601"); | ||
return calendar; | ||
}; | ||
}, | ||
}); | ||
|
||
const result = Temporal.now.date("UTC", "iso8601"); | ||
assert.sameValue(result instanceof Temporal.Date, true); | ||
for (const property of ["year", "month", "day"]) { | ||
assert.sameValue(result[property], dateTime[property], property); | ||
} | ||
|
||
assert.compareArray(actual, expected); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// Copyright (C) 2020 Igalia, S.L. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
esid: sec-temporal.now.datetime | ||
---*/ | ||
|
||
const values = [ | ||
[null, "null"], | ||
[true, "true"], | ||
["iso8601", "iso8601"], | ||
[2020, "2020"], | ||
[2n, "2"], | ||
]; | ||
|
||
const calendar = Temporal.Calendar.from("iso8601"); | ||
const original = Temporal.Calendar.from; | ||
for (const [input, output] of values) { | ||
Temporal.Calendar.from = function(argument) { | ||
assert.sameValue(argument, output); | ||
// TODO: Remove. | ||
Temporal.Calendar.from = original; | ||
return calendar; | ||
}; | ||
|
||
Temporal.now.dateTime("UTC", input); | ||
} | ||
|
||
Temporal.Calendar.from = function() { | ||
throw new Test262Error("Should not call Calendar.from"); | ||
}; | ||
|
||
assert.throws(TypeError, () => Temporal.now.dateTime("UTC", Symbol())); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// Copyright (C) 2020 Igalia, S.L. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
esid: sec-temporal.now.datetime | ||
includes: [compareArray.js] | ||
---*/ | ||
|
||
const actual = []; | ||
const expected = [ | ||
"get Temporal.Calendar.from", | ||
"get timeZone.getDateTimeFor", | ||
"call timeZone.getDateTimeFor", | ||
]; | ||
const dateTime = Temporal.DateTime.from("1963-07-02T12:34:56.987654321"); | ||
|
||
const timeZone = new Proxy({ | ||
getDateTimeFor(absolute, calendar) { | ||
actual.push("call timeZone.getDateTimeFor"); | ||
assert.sameValue(absolute instanceof Temporal.Absolute, true, "Absolute"); | ||
assert.sameValue(calendar instanceof Temporal.Calendar, true, "Calendar"); | ||
assert.sameValue(calendar.id, "japanese"); | ||
return dateTime; | ||
}, | ||
}, { | ||
has(target, property) { | ||
actual.push(`has timeZone.${property}`); | ||
return property in target; | ||
}, | ||
get(target, property) { | ||
actual.push(`get timeZone.${property}`); | ||
return target[property]; | ||
}, | ||
}); | ||
|
||
Object.defineProperty(Temporal.Calendar, "from", { | ||
get() { | ||
actual.push("get Temporal.Calendar.from"); | ||
return undefined; | ||
}, | ||
}); | ||
|
||
const result = Temporal.now.dateTime(timeZone, "japanese"); | ||
assert.sameValue(result, dateTime); | ||
|
||
assert.compareArray(actual, expected); |
Oops, something went wrong.