summaryrefslogtreecommitdiff
path: root/Userland
diff options
context:
space:
mode:
authordavidot <davidot@serenityos.org>2022-10-13 23:30:51 +0200
committerLinus Groh <mail@linusgroh.de>2022-10-14 11:23:50 +0200
commit1b0ca52c54ea21fd5d4f13926273b1601eda9791 (patch)
tree2d3bddf4fc6f634528503d2c27a7be7dcc806a05 /Userland
parent1167fdb17ad9452a0f704a24c19b1d907055757c (diff)
downloadserenity-1b0ca52c54ea21fd5d4f13926273b1601eda9791.zip
LibJS: Disallow one day long time zone offsets
This is a normative change in the Temporal spec. See: https://github.com/tc39/proposal-temporal/commit/9cc8b29b
Diffstat (limited to 'Userland')
-rw-r--r--Userland/Libraries/LibJS/Runtime/ErrorTypes.h3
-rw-r--r--Userland/Libraries/LibJS/Runtime/Temporal/TimeZone.cpp4
-rw-r--r--Userland/Libraries/LibJS/Tests/builtins/Temporal/Now/Now.plainDate.js17
-rw-r--r--Userland/Libraries/LibJS/Tests/builtins/Temporal/Now/Now.plainDateISO.js16
-rw-r--r--Userland/Libraries/LibJS/Tests/builtins/Temporal/Now/Now.plainDateTime.js19
-rw-r--r--Userland/Libraries/LibJS/Tests/builtins/Temporal/Now/Now.plainDateTimeISO.js18
-rw-r--r--Userland/Libraries/LibJS/Tests/builtins/Temporal/Now/Now.plainTimeISO.js16
7 files changed, 83 insertions, 10 deletions
diff --git a/Userland/Libraries/LibJS/Runtime/ErrorTypes.h b/Userland/Libraries/LibJS/Runtime/ErrorTypes.h
index 304e051dfa..cdf19cee9f 100644
--- a/Userland/Libraries/LibJS/Runtime/ErrorTypes.h
+++ b/Userland/Libraries/LibJS/Runtime/ErrorTypes.h
@@ -246,7 +246,8 @@
M(TemporalInvalidMonthCode, "Invalid month code") \
M(TemporalInvalidMonthDayString, "Invalid month day string '{}'") \
M(TemporalInvalidMonthDayStringUTCDesignator, "Invalid month day string '{}': must not contain a UTC designator") \
- M(TemporalInvalidOffsetNanosecondsValue, "Invalid offset nanoseconds value, must be in range -86400 * 10^9 to 86400 * 10^9") \
+ M(TemporalInvalidOffsetNanosecondsValue, "Invalid offset nanoseconds value, must be in range -86400 * 10^9 + 1 to " \
+ "86400 * 10^9 - 1") \
M(TemporalInvalidPlainDate, "Invalid plain date") \
M(TemporalInvalidPlainDateTime, "Invalid plain date time") \
M(TemporalInvalidPlainMonthDay, "Invalid plain month day") \
diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/TimeZone.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/TimeZone.cpp
index 1bc1faa152..095e7b699c 100644
--- a/Userland/Libraries/LibJS/Runtime/Temporal/TimeZone.cpp
+++ b/Userland/Libraries/LibJS/Runtime/Temporal/TimeZone.cpp
@@ -492,8 +492,8 @@ ThrowCompletionOr<double> get_offset_nanoseconds_for(VM& vm, Value time_zone, In
// 5. Set offsetNanoseconds to ℝ(offsetNanoseconds).
auto offset_nanoseconds = offset_nanoseconds_value.as_double();
- // 6. If abs(offsetNanoseconds) > nsPerDay, throw a RangeError exception.
- if (fabs(offset_nanoseconds) > ns_per_day)
+ // 6. If abs(offsetNanoseconds) ≥ nsPerDay, throw a RangeError exception.
+ if (fabs(offset_nanoseconds) >= ns_per_day)
return vm.throw_completion<RangeError>(ErrorType::TemporalInvalidOffsetNanosecondsValue);
// 7. Return offsetNanoseconds.
diff --git a/Userland/Libraries/LibJS/Tests/builtins/Temporal/Now/Now.plainDate.js b/Userland/Libraries/LibJS/Tests/builtins/Temporal/Now/Now.plainDate.js
index db7ce944ec..d6680316f9 100644
--- a/Userland/Libraries/LibJS/Tests/builtins/Temporal/Now/Now.plainDate.js
+++ b/Userland/Libraries/LibJS/Tests/builtins/Temporal/Now/Now.plainDate.js
@@ -14,7 +14,7 @@ describe("correct behavior", () => {
const calendar = new Temporal.Calendar("iso8601");
const timeZone = {
getOffsetNanosecondsFor() {
- return 86400000000000;
+ return 86399999999999;
},
};
const plainDate = Temporal.Now.plainDate(calendar, "UTC");
@@ -34,6 +34,21 @@ describe("correct behavior", () => {
}
}
});
+
+ test("cannot have a time zone with more than a day", () => {
+ [86400000000000, -86400000000000, 86400000000001, 86400000000002].forEach(offset => {
+ const calendar = new Temporal.Calendar("iso8601");
+ const timeZone = {
+ getOffsetNanosecondsFor() {
+ return offset;
+ },
+ };
+ expect(() => Temporal.Now.plainDate(calendar, timeZone)).toThrowWithMessage(
+ RangeError,
+ "Invalid offset nanoseconds value, must be in range -86400 * 10^9 + 1 to 86400 * 10^9 - 1"
+ );
+ });
+ });
});
describe("errors", () => {
diff --git a/Userland/Libraries/LibJS/Tests/builtins/Temporal/Now/Now.plainDateISO.js b/Userland/Libraries/LibJS/Tests/builtins/Temporal/Now/Now.plainDateISO.js
index 1d44a58719..094f41cb67 100644
--- a/Userland/Libraries/LibJS/Tests/builtins/Temporal/Now/Now.plainDateISO.js
+++ b/Userland/Libraries/LibJS/Tests/builtins/Temporal/Now/Now.plainDateISO.js
@@ -12,7 +12,7 @@ describe("correct behavior", () => {
test("custom time zone", () => {
const timeZone = {
getOffsetNanosecondsFor() {
- return 86400000000000;
+ return 86399999999999;
},
};
const plainDate = Temporal.Now.plainDateISO("UTC");
@@ -32,6 +32,20 @@ describe("correct behavior", () => {
}
}
});
+
+ test("cannot have a time zone with more than a day", () => {
+ [86400000000000, -86400000000000, 86400000000001, 86400000000002].forEach(offset => {
+ const timeZone = {
+ getOffsetNanosecondsFor() {
+ return offset;
+ },
+ };
+ expect(() => Temporal.Now.plainDateISO(timeZone)).toThrowWithMessage(
+ RangeError,
+ "Invalid offset nanoseconds value, must be in range -86400 * 10^9 + 1 to 86400 * 10^9 - 1"
+ );
+ });
+ });
});
describe("errors", () => {
diff --git a/Userland/Libraries/LibJS/Tests/builtins/Temporal/Now/Now.plainDateTime.js b/Userland/Libraries/LibJS/Tests/builtins/Temporal/Now/Now.plainDateTime.js
index 3fc3791b30..65ba7fbf3a 100644
--- a/Userland/Libraries/LibJS/Tests/builtins/Temporal/Now/Now.plainDateTime.js
+++ b/Userland/Libraries/LibJS/Tests/builtins/Temporal/Now/Now.plainDateTime.js
@@ -33,7 +33,7 @@ describe("correct behavior", () => {
const calendar = new Temporal.Calendar("iso8601");
const timeZone = {
getOffsetNanosecondsFor() {
- return 86400000000000;
+ return 86399999999999;
},
};
@@ -54,7 +54,7 @@ describe("correct behavior", () => {
const calendar = new Temporal.Calendar("iso8601");
const timeZone = {
getOffsetNanosecondsFor() {
- return -86400000000000;
+ return -86399999999999;
},
};
@@ -72,6 +72,21 @@ describe("correct behavior", () => {
});
expect(timeZoneTested).toBeTrue();
+
+ test("cannot have a time zone with more than a day", () => {
+ [86400000000000, -86400000000000, 86400000000001, 86400000000002].forEach(offset => {
+ const calendar = new Temporal.Calendar("iso8601");
+ const timeZone = {
+ getOffsetNanosecondsFor() {
+ return offset;
+ },
+ };
+ expect(() => Temporal.Now.plainDateTime(calendar, timeZone)).toThrowWithMessage(
+ RangeError,
+ "Invalid offset nanoseconds value, must be in range -86400 * 10^9 + 1 to 86400 * 10^9 - 1"
+ );
+ });
+ });
});
describe("errors", () => {
diff --git a/Userland/Libraries/LibJS/Tests/builtins/Temporal/Now/Now.plainDateTimeISO.js b/Userland/Libraries/LibJS/Tests/builtins/Temporal/Now/Now.plainDateTimeISO.js
index 540bbd3c2c..587deb2f29 100644
--- a/Userland/Libraries/LibJS/Tests/builtins/Temporal/Now/Now.plainDateTimeISO.js
+++ b/Userland/Libraries/LibJS/Tests/builtins/Temporal/Now/Now.plainDateTimeISO.js
@@ -31,7 +31,7 @@ describe("correct behavior", () => {
test("custom time zone positive", () => {
const timeZone = {
getOffsetNanosecondsFor() {
- return 86400000000000;
+ return 86399999999999;
},
};
@@ -51,7 +51,7 @@ describe("correct behavior", () => {
test("custom time zone negative", () => {
const timeZone = {
getOffsetNanosecondsFor() {
- return -86400000000000;
+ return -86399999999999;
},
};
@@ -69,6 +69,20 @@ describe("correct behavior", () => {
});
expect(timeZoneTested).toBeTrue();
+
+ test("cannot have a time zone with more than a day", () => {
+ [86400000000000, -86400000000000, 86400000000001, 86400000000002].forEach(offset => {
+ const timeZone = {
+ getOffsetNanosecondsFor() {
+ return offset;
+ },
+ };
+ expect(() => Temporal.Now.plainDateTimeISO(timeZone)).toThrowWithMessage(
+ RangeError,
+ "Invalid offset nanoseconds value, must be in range -86400 * 10^9 + 1 to 86400 * 10^9 - 1"
+ );
+ });
+ });
});
describe("errors", () => {
diff --git a/Userland/Libraries/LibJS/Tests/builtins/Temporal/Now/Now.plainTimeISO.js b/Userland/Libraries/LibJS/Tests/builtins/Temporal/Now/Now.plainTimeISO.js
index 0199f65157..993e6f6bf0 100644
--- a/Userland/Libraries/LibJS/Tests/builtins/Temporal/Now/Now.plainTimeISO.js
+++ b/Userland/Libraries/LibJS/Tests/builtins/Temporal/Now/Now.plainTimeISO.js
@@ -12,13 +12,27 @@ describe("correct behavior", () => {
test("custom time zone", () => {
const timeZone = {
getOffsetNanosecondsFor() {
- return 86400000000000;
+ return 86399999999999;
},
};
const plainTime = Temporal.Now.plainTimeISO("UTC");
const plainTimeWithOffset = Temporal.Now.plainTimeISO(timeZone);
// FIXME: Compare these in a sensible way
});
+
+ test("cannot have a time zone with more than a day", () => {
+ [86400000000000, -86400000000000, 86400000000001, 86400000000002].forEach(offset => {
+ const timeZone = {
+ getOffsetNanosecondsFor() {
+ return offset;
+ },
+ };
+ expect(() => Temporal.Now.plainTimeISO(timeZone)).toThrowWithMessage(
+ RangeError,
+ "Invalid offset nanoseconds value, must be in range -86400 * 10^9 + 1 to 86400 * 10^9 - 1"
+ );
+ });
+ });
});
describe("errors", () => {