Skip to content

Commit

Permalink
PR feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
jessealama committed Apr 12, 2022
1 parent 31b28d8 commit 07c2636
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 78 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,20 @@ includes: [temporalHelpers.js]
const dt = new Temporal.PlainDateTime(1976, 11, 18, 14, 23, 30, 123, 456, 789);

const incrementOneCeil = {
"day": [1976, 11, "M11", 19, 0, 0, 0, 0, 0, 0, 0],
"hour": [1976, 11, "M11", 18, 15, 0, 0, 0, 0, 0, 0],
"minute": [1976, 11, "M11", 18, 14, 24, 0, 0, 0, 0],
"second": [1976, 11, "M11", 18, 14, 23, 31, 0, 0, 0],
"millisecond": [1976, 11, "M11", 18, 14, 23, 30, 124, 0, 0],
"microsecond": [1976, 11, "M11", 18, 14, 23, 30, 123, 457, 0],
"nanosecond": [1976, 11, "M11", 18, 14, 23, 30, 123, 456, 789]
"day": [1976, 11, "M11", 19, 0, 0, 0, 0, 0, 0],
"hour": [1976, 11, "M11", 18, 15, 0, 0, 0, 0, 0],
"minute": [1976, 11, "M11", 18, 14, 24, 0, 0, 0, 0],
"second": [1976, 11, "M11", 18, 14, 23, 31, 0, 0, 0],
"millisecond": [1976, 11, "M11", 18, 14, 23, 30, 124, 0, 0],
"microsecond": [1976, 11, "M11", 18, 14, 23, 30, 123, 457, 0],
"nanosecond": [1976, 11, "M11", 18, 14, 23, 30, 123, 456, 789]
};

Object.entries(incrementOneCeil).forEach(([smallestUnit, expected]) => {
const [y, mon, code, d, h, min, s, ms, µs, ns] = expected;
TemporalHelpers.assertPlainDateTime(
dt.round({ smallestUnit, roundingMode: "ceil" }),
y, mon, code, d, h, min, s, ms, µs, ns,
`rounds up to ${smallestUnit} (ceil)`
...expected,
`rounds up to ${smallestUnit} (ceil)`,
undefined
);
});
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,19 @@ includes: [temporalHelpers.js]
const dt = new Temporal.PlainDateTime(1976, 11, 18, 14, 23, 30, 123, 456, 789);

const incrementOneFloor = {
"day": [1976, 11, "M11", 18, 0, 0, 0, 0, 0, 0, 0],
"hour": [1976, 11, "M11", 18, 14, 0, 0, 0, 0, 0, 0],
"minute": [1976, 11, "M11", 18, 14, 23, 0, 0, 0, 0],
"second": [1976, 11, "M11", 18, 14, 23, 30, 0, 0, 0],
"millisecond": [1976, 11, "M11", 18, 14, 23, 30, 123, 0, 0],
"microsecond": [1976, 11, "M11", 18, 14, 23, 30, 123, 456, 0],
"nanosecond": [1976, 11, "M11", 18, 14, 23, 30, 123, 456, 789]
"day": [1976, 11, "M11", 18, 0, 0, 0, 0, 0, 0],
"hour": [1976, 11, "M11", 18, 14, 0, 0, 0, 0, 0],
"minute": [1976, 11, "M11", 18, 14, 23, 0, 0, 0, 0],
"second": [1976, 11, "M11", 18, 14, 23, 30, 0, 0, 0],
"millisecond": [1976, 11, "M11", 18, 14, 23, 30, 123, 0, 0],
"microsecond": [1976, 11, "M11", 18, 14, 23, 30, 123, 456, 0],
"nanosecond": [1976, 11, "M11", 18, 14, 23, 30, 123, 456, 789]
};

Object.entries(incrementOneFloor).forEach(([smallestUnit, expected]) => {
const [y, mon, code, d, h, min, s, ms, µs, ns] = expected;
TemporalHelpers.assertPlainDateTime(
dt.round({ smallestUnit, roundingMode: "floor" }),
y, mon, code, d, h, min, s, ms, µs, ns,
...expected,
`rounds down to ${smallestUnit} (floor)`
);
});
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,20 @@ includes: [temporalHelpers.js]
const dt = new Temporal.PlainDateTime(1976, 11, 18, 14, 23, 30, 123, 456, 789);

const incrementOneNearest = {
"day": [1976, 11, "M11", 19, 0, 0, 0, 0, 0, 0, 0],
"hour": [1976, 11, "M11", 18, 14, 0, 0, 0, 0, 0, 0],
"minute": [1976, 11, "M11", 18, 14, 24, 0, 0, 0, 0],
"second": [1976, 11, "M11", 18, 14, 23, 30, 0, 0, 0],
"millisecond": [1976, 11, "M11", 18, 14, 23, 30, 123, 0, 0],
"microsecond": [1976, 11, "M11", 18, 14, 23, 30, 123, 457, 0],
"nanosecond": [1976, 11, "M11", 18, 14, 23, 30, 123, 456, 789]
"day": [1976, 11, "M11", 19, 0, 0, 0, 0, 0, 0],
"hour": [1976, 11, "M11", 18, 14, 0, 0, 0, 0, 0],
"minute": [1976, 11, "M11", 18, 14, 24, 0, 0, 0, 0],
"second": [1976, 11, "M11", 18, 14, 23, 30, 0, 0, 0],
"millisecond": [1976, 11, "M11", 18, 14, 23, 30, 123, 0, 0],
"microsecond": [1976, 11, "M11", 18, 14, 23, 30, 123, 457, 0],
"nanosecond": [1976, 11, "M11", 18, 14, 23, 30, 123, 456, 789]
};

Object.entries(incrementOneNearest).forEach(([smallestUnit, expected]) => {
const [y, mon, code, d, h, min, s, ms, µs, ns] = expected;
TemporalHelpers.assertPlainDateTime(
dt.round({ smallestUnit, roundingMode: "halfExpand" }),
y, mon, code, d, h, min, s, ms, µs, ns,
`rounds to nearest ${smallestUnit} (half-expand)`
...expected,
`rounds to nearest ${smallestUnit} (half-expand)`,
undefined
);
});
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,27 @@ includes: [temporalHelpers.js]

const dt = new Temporal.PlainDateTime(1976, 11, 18, 14, 23, 30, 123, 456, 789);

const units = ["day", "hour", "minute", "second", "millisecond", "microsecond", "nanosecond"];
const units = {
"day": [1976, 11, "M11", 19, 0, 0, 0, 0, 0, 0],
"hour": [1976, 11, "M11", 18, 14, 0, 0, 0, 0, 0],
"minute": [1976, 11, "M11", 18, 14, 24, 0, 0, 0, 0],
"second": [1976, 11, "M11", 18, 14, 23, 30, 0, 0, 0],
"millisecond": [1976, 11, "M11", 18, 14, 23, 30, 123, 0, 0],
"microsecond": [1976, 11, "M11", 18, 14, 23, 30, 123, 457, 0],
"nanosecond": [1976, 11, "M11", 18, 14, 23, 30, 123, 456, 789]
};

units.forEach((unit) => {
TemporalHelpers.assertPlainDateTimesEqual(
const expected = [1976, 11, "M11", 18, 0, 0, 0, 0, 0, 0];

Object.entries(units).forEach(([unit, expected]) => {
TemporalHelpers.assertPlainDateTime(
dt.round({ roundingmode: "halfExpand", smallestUnit: unit }),
...expected,
`halfExpand is the default (smallest unit = ${unit}, rounding mode present)`
);
TemporalHelpers.assertPlainDateTime(
dt.round({ smallestUnit: unit }),
`halfExpand is the default (smallest unit = ${unit})`
...expected,
`halfExpand is the default (smallest unit = ${unit}, rounding mode absent)`
);
});
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,19 @@ includes: [temporalHelpers.js]
const dt = new Temporal.PlainDateTime(1976, 11, 18, 14, 23, 30, 123, 456, 789);

const incrementOneFloor = {
"day": [1976, 11, "M11", 18, 0, 0, 0, 0, 0, 0, 0],
"hour": [1976, 11, "M11", 18, 14, 0, 0, 0, 0, 0, 0],
"minute": [1976, 11, "M11", 18, 14, 23, 0, 0, 0, 0],
"second": [1976, 11, "M11", 18, 14, 23, 30, 0, 0, 0],
"millisecond": [1976, 11, "M11", 18, 14, 23, 30, 123, 0, 0],
"microsecond": [1976, 11, "M11", 18, 14, 23, 30, 123, 456, 0],
"nanosecond": [1976, 11, "M11", 18, 14, 23, 30, 123, 456, 789]
"day": [1976, 11, "M11", 18, 0, 0, 0, 0, 0, 0],
"hour": [1976, 11, "M11", 18, 14, 0, 0, 0, 0, 0],
"minute": [1976, 11, "M11", 18, 14, 23, 0, 0, 0, 0],
"second": [1976, 11, "M11", 18, 14, 23, 30, 0, 0, 0],
"millisecond": [1976, 11, "M11", 18, 14, 23, 30, 123, 0, 0],
"microsecond": [1976, 11, "M11", 18, 14, 23, 30, 123, 456, 0],
"nanosecond": [1976, 11, "M11", 18, 14, 23, 30, 123, 456, 789]
};

Object.entries(incrementOneFloor).forEach(([smallestUnit, expected]) => {
const [y, mon, code, d, h, min, s, ms, µs, ns] = expected;
TemporalHelpers.assertPlainDateTime(
dt.round({ smallestUnit, roundingMode: "trunc" }),
y, mon, code, d, h, min, s, ms, µs, ns,
...expected,
`truncates to ${smallestUnit}`
);
});

0 comments on commit 07c2636

Please sign in to comment.