Skip to content
Permalink
Browse files
Temporal.PlainTime#since should handle ceil/floor properly
https://bugs.webkit.org/show_bug.cgi?id=241623

Reviewed by Yusuke Suzuki.

This patch adds a spec step that our implementation was missing:

    DifferenceTemporalPlainTime ( operation, temporalTime, other, options )
        ...
        9. If operation is ~since~, then
            a. Set roundingMode to ! NegateTemporalRoundingMode(roundingMode).

* JSTests/test262/expectations.yaml:
Mark four test cases as passing.

* Source/JavaScriptCore/runtime/TemporalPlainTime.cpp:
(JSC::TemporalPlainTime::since const):

Canonical link: https://commits.webkit.org/251555@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@295550 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
rkirsling committed Jun 15, 2022
1 parent ea2a58d commit 671dafff00a3ff815cd104d533dae207f97898a0
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
@@ -1080,12 +1080,6 @@ test/built-ins/Temporal/PlainTime/prototype/equals/argument-zoneddatetime-timezo
test/built-ins/Temporal/PlainTime/prototype/since/argument-zoneddatetime-timezone-getoffsetnanosecondsfor-not-callable.js:
default: "TypeError: undefined is not a constructor (evaluating 'new Temporal.ZonedDateTime(1_000_000_000_987_654_321n, timeZone)')"
strict mode: "TypeError: undefined is not a constructor (evaluating 'new Temporal.ZonedDateTime(1_000_000_000_987_654_321n, timeZone)')"
test/built-ins/Temporal/PlainTime/prototype/since/roundingmode-ceil.js:
default: 'Test262Error: hours hours result Expected SameValue(«4», «5») to be true'
strict mode: 'Test262Error: hours hours result Expected SameValue(«4», «5») to be true'
test/built-ins/Temporal/PlainTime/prototype/since/roundingmode-floor.js:
default: 'Test262Error: hours hours result Expected SameValue(«5», «4») to be true'
strict mode: 'Test262Error: hours hours result Expected SameValue(«5», «4») to be true'
test/built-ins/Temporal/PlainTime/prototype/until/argument-zoneddatetime-timezone-getoffsetnanosecondsfor-not-callable.js:
default: "TypeError: undefined is not a constructor (evaluating 'new Temporal.ZonedDateTime(1_000_000_000_987_654_321n, timeZone)')"
strict mode: "TypeError: undefined is not a constructor (evaluating 'new Temporal.ZonedDateTime(1_000_000_000_987_654_321n, timeZone)')"
@@ -647,6 +647,12 @@ ISO8601::Duration TemporalPlainTime::since(JSGlobalObject* globalObject, Tempora
auto [smallestUnit, largestUnit, roundingMode, increment] = extractDifferenceOptions(globalObject, optionsValue);
RETURN_IF_EXCEPTION(scope, { });

// https://tc39.es/proposal-temporal/#sec-temporal-negatetemporalroundingmode
if (roundingMode == RoundingMode::Ceil)
roundingMode = RoundingMode::Floor;
else if (roundingMode == RoundingMode::Floor)
roundingMode = RoundingMode::Ceil;

auto result = differenceTime(other->plainTime(), plainTime());
result = -result;
result.setYears(0);

0 comments on commit 671daff

Please sign in to comment.