Skip to content

Rebase through early October 2024 #312

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

Merged
merged 22 commits into from
Mar 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
6ee9d43
Editorial: Split total() code path out of RoundRelativeDuration
ptomato Sep 25, 2024
0e4efbe
Editorial: Recommend "remapping" for dates exceeding era year bounds
gibson042 Sep 30, 2024
2907efa
Editorial: Simplify ISO Date Record in PlainDate.p.toZonedDateTime
ptomato Sep 30, 2024
c836ea6
Polyfill: 0-based month in ISODateToEpochDays
ptomato Sep 30, 2024
0fafc55
Editorial: Adjust RangeError condition in ToTemporalInstant
ptomato Sep 30, 2024
d856759
Editorial: Adjust RangeError condition in GetPossibleEpochNanoseconds
ptomato Oct 1, 2024
f40de60
Editorial: Adjust RangeError condition in InterpretISODateTimeOffset
ptomato Oct 1, 2024
ff5c5b1
Editorial: Deduplicate ISODateTimeToDateRecord in NudgeToCalendarUnit
ptomato Oct 1, 2024
0031284
Editorial: Use ISODateTimeToDateRecord in more places
ptomato Oct 1, 2024
d69245f
Editorial: Don't pass ISO Date-Time when ISO Date Record is expected
ptomato Oct 1, 2024
cfdecf2
Editorial: Move DifferenceISODate into CalendarDateDifference
ptomato Oct 4, 2024
6916bb0
Editorial: Replace RegulateISOYearMonth with RegulateISODate
ptomato Oct 4, 2024
07e8b25
Editorial: Move ISOMonthDayFromFields into CalendarMonthDayFromFields
ptomato Oct 4, 2024
b5ce486
Editorial: Include ISO 8601 algorithm in CalendarDateToISO
ptomato Oct 4, 2024
12bfd2a
Editorial: Merge CalendarDateAddition into CalendarDateAdd
ptomato Oct 4, 2024
732d4de
Polyfill: Deduplicate calendar daysInMonth implementation
ptomato Oct 4, 2024
4b5bc52
Editorial: Include ISO 8601 algorithms in CalendarISOToDate
ptomato Oct 4, 2024
12a54d8
Editorial: Include ISO 8601 algorithm in CalendarResolveFields
ptomato Oct 4, 2024
b39125a
Editorial: Remove individual AOs for each calendar field
ptomato Oct 5, 2024
6ae3ca4
Polyfill: Make day-of-week algorithm less opaque
ptomato Oct 7, 2024
506f504
Polyfill: Make buildMonthCode less opaque
ptomato Oct 7, 2024
81603f4
Polyfill: Refactor GetIntrinsic('%calendarImpl%')(calendar) into func…
ptomato Oct 7, 2024
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
425 changes: 200 additions & 225 deletions lib/calendar.ts

Large diffs are not rendered by default.

38 changes: 10 additions & 28 deletions lib/duration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import {

// class static functions and methods
MathAbs,
NumberIsNaN,
ObjectDefineProperty,

// miscellaneous
Expand Down Expand Up @@ -235,7 +234,7 @@ export class Duration implements Temporal.Duration {
const calendar = GetSlot(zonedRelativeTo, CALENDAR);
const relativeEpochNs = GetSlot(zonedRelativeTo, EPOCHNANOSECONDS);
const targetEpochNs = ES.AddZonedDateTime(relativeEpochNs, timeZone, calendar, duration);
({ duration } = ES.DifferenceZonedDateTimeWithRounding(
duration = ES.DifferenceZonedDateTimeWithRounding(
relativeEpochNs,
targetEpochNs,
timeZone,
Expand All @@ -244,7 +243,7 @@ export class Duration implements Temporal.Duration {
roundingIncrement,
smallestUnit,
roundingMode
));
);
if (ES.TemporalUnitCategory(largestUnit) === 'date') largestUnit = 'hour';
return ES.UnnormalizeDuration(duration, largestUnit);
}
Expand All @@ -259,7 +258,7 @@ export class Duration implements Temporal.Duration {
const dateDuration = ES.AdjustDateDurationRecord(duration.date, targetTime.deltaDays);
const targetDate = ES.CalendarDateAdd(calendar, isoRelativeToDate, dateDuration, 'constrain');

({ duration } = ES.DifferencePlainDateTimeWithRounding(
duration = ES.DifferencePlainDateTimeWithRounding(
isoRelativeToDate.year,
isoRelativeToDate.month,
isoRelativeToDate.day,
Expand All @@ -283,7 +282,7 @@ export class Duration implements Temporal.Duration {
roundingIncrement,
smallestUnit,
roundingMode
));
);
return ES.UnnormalizeDuration(duration, largestUnit);
}

Expand All @@ -296,7 +295,7 @@ export class Duration implements Temporal.Duration {
}
assert(!ES.IsCalendarUnit(smallestUnit), 'smallestUnit was larger than largestUnit');
let duration = ES.NormalizeDurationWith24HourDays(this);
({ duration } = ES.RoundTimeDuration(duration, roundingIncrement, smallestUnit, roundingMode));
duration = ES.RoundTimeDuration(duration, roundingIncrement, smallestUnit, roundingMode);
return ES.UnnormalizeDuration(duration, largestUnit);
}
total(optionsParam: Params['total'][0]): Return['total'] {
Expand All @@ -316,18 +315,7 @@ export class Duration implements Temporal.Duration {
const calendar = GetSlot(zonedRelativeTo, CALENDAR);
const relativeEpochNs = GetSlot(zonedRelativeTo, EPOCHNANOSECONDS);
const targetEpochNs = ES.AddZonedDateTime(relativeEpochNs, timeZone, calendar, duration);
const { total } = ES.DifferenceZonedDateTimeWithRounding(
relativeEpochNs,
targetEpochNs,
timeZone,
calendar,
unit,
1,
unit,
'trunc'
);
assert(!NumberIsNaN(total), 'total went through NudgeToZonedTime code path');
return total;
return ES.DifferenceZonedDateTimeWithTotal(relativeEpochNs, targetEpochNs, timeZone, calendar, unit);
}

if (plainRelativeTo) {
Expand All @@ -340,7 +328,7 @@ export class Duration implements Temporal.Duration {
const dateDuration = ES.AdjustDateDurationRecord(duration.date, targetTime.deltaDays);
const targetDate = ES.CalendarDateAdd(calendar, isoRelativeToDate, dateDuration, 'constrain');

const { total } = ES.DifferencePlainDateTimeWithRounding(
return ES.DifferencePlainDateTimeWithTotal(
isoRelativeToDate.year,
isoRelativeToDate.month,
isoRelativeToDate.day,
Expand All @@ -360,13 +348,8 @@ export class Duration implements Temporal.Duration {
targetTime.microsecond,
targetTime.nanosecond,
calendar,
unit,
1,
unit,
'trunc'
unit
);
assert(!NumberIsNaN(total), 'total went through NudgeToZonedTime code path');
return total;
}

// No reference date to calculate difference relative to
Expand All @@ -378,8 +361,7 @@ export class Duration implements Temporal.Duration {
throw new RangeErrorCtor(`a starting point is required for ${unit}s total`);
}
const duration = ES.NormalizeDurationWith24HourDays(this);
const { total } = ES.RoundTimeDuration(duration, 1, unit, 'trunc');
return total;
return ES.TotalTimeDuration(duration.norm, unit);
}
toString(options: Params['toString'][0] = undefined): string {
if (!ES.IsTemporalDuration(this)) throw new TypeErrorCtor('invalid receiver');
Expand All @@ -400,7 +382,7 @@ export class Duration implements Temporal.Duration {

const largestUnit = ES.DefaultTemporalLargestUnit(this);
let duration = ES.NormalizeDuration(this);
({ duration } = ES.RoundTimeDuration(duration, increment, unit, roundingMode));
duration = ES.RoundTimeDuration(duration, increment, unit, roundingMode);
const roundedDuration = ES.UnnormalizeDuration(duration, ES.LargerOfTwoTemporalUnits(largestUnit, 'second'));
return ES.TemporalDurationToString(roundedDuration, precision);
}
Expand Down
Loading