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

Update temporalHelpers.js #3861

Merged
merged 1 commit into from
Jul 11, 2023
Merged
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
30 changes: 28 additions & 2 deletions harness/temporalHelpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,26 @@ var TemporalHelpers = {
assert.sameValue(duration.nanoseconds, nanoseconds, `${description} nanoseconds result`);
},

/*
* assertDateDuration(duration, years, months, weeks, days, [, description]):
*
* Shorthand for asserting that each date field of a Temporal.Duration is
* equal to an expected value.
*/
assertDateDuration(duration, years, months, weeks, days, description = "") {
assert(duration instanceof Temporal.Duration, `${description} instanceof`);
assert.sameValue(duration.years, years, `${description} years result`);
assert.sameValue(duration.months, months, `${description} months result`);
assert.sameValue(duration.weeks, weeks, `${description} weeks result`);
assert.sameValue(duration.days, days, `${description} days result`);
assert.sameValue(duration.hours, 0, `${description} hours result should be zero`);
assert.sameValue(duration.minutes, 0, `${description} minutes result should be zero`);
assert.sameValue(duration.seconds, 0, `${description} seconds result should be zero`);
assert.sameValue(duration.milliseconds, 0, `${description} milliseconds result should be zero`);
assert.sameValue(duration.microseconds, 0, `${description} microseconds result should be zero`);
assert.sameValue(duration.nanoseconds, 0, `${description} nanoseconds result should be zero`);
},

/*
* assertDurationsEqual(actual, expected[, description]):
*
Expand Down Expand Up @@ -1784,8 +1804,14 @@ var TemporalHelpers = {
return this._offsetValue;
}

getPossibleInstantsFor() {
return [];
getPossibleInstantsFor(dt) {
if (typeof this._offsetValue !== 'number' || Math.abs(this._offsetValue) >= 86400e9 || isNaN(this._offsetValue)) return [];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think if any of these conditions are true, the test helper is being misused ... but I don't mind having this here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I remember correctly, I did it this way so that tests would fail in the right place in cases where the offset was invalid: either not a number or out of range. Otherwise, the failures would happen in the next line here in temporalHelpers, instead of actually exercising Temporal implementations' ability to reject invalid offset time zone IDs.

const zdt = dt.toZonedDateTime("UTC").add({ nanoseconds: -this._offsetValue });
return [zdt.toInstant()];
}

get id() {
return this.getOffsetStringFor(new Temporal.Instant(0n));
}
}
return new SpecificOffsetTimeZone(offsetValue);
Expand Down