Skip to content

Commit

Permalink
Initial fix for merge conflicts (will rebase soon)
Browse files Browse the repository at this point in the history
  • Loading branch information
justingrant committed Jun 13, 2020
1 parent 3f9a63e commit c589c47
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 20 deletions.
9 changes: 5 additions & 4 deletions polyfill/lib/date.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -125,12 +125,13 @@ export class Date {
difference(other, options) {
if (!ES.IsTemporalDate(this)) throw new TypeError('invalid receiver');
if (!ES.IsTemporalDate(other)) throw new TypeError('invalid Date object');
const largestUnit = ES.ToLargestTemporalUnit(options, 'days', ['hours', 'minutes', 'seconds']);
const calendar = GetSlot(this, CALENDAR);
if (calendar.id !== GetSlot(other, CALENDAR).id) {
other = new Date(GetSlot(other, ISO_YEAR), GetSlot(other, ISO_MONTH), GetSlot(other, ISO_DAY), calendar);
}
const comparison = Date.compare(this, other);
if (comparison < 0) throw new RangeError('other instance cannot be larger than `this`');
const { years, months, weeks, days } = ES.DifferenceDate(other, this, largestUnit);
const Duration = GetIntrinsic('%Temporal.Duration%');
return new Duration(years, months, weeks, days, 0, 0, 0, 0, 0, 0);
return calendar.difference(other, this, options);
}
equals(other) {
if (!ES.IsTemporalDate(this)) throw new TypeError('invalid receiver');
Expand Down
8 changes: 4 additions & 4 deletions polyfill/lib/datetime.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -245,17 +245,17 @@ export class DateTime {
other,
this
);
let { year, month, day } = this;
day += deltaDays;
let year = GetSlot(larger, ISO_YEAR);
let month = GetSlot(larger, ISO_MONTH);
let day = GetSlot(larger, ISO_DAY) + deltaDays;
({ year, month, day } = ES.BalanceDate(year, month, day));

let dateLargestUnit = 'days';
if (largestUnit === 'years' || largestUnit === 'months' || largestUnit === 'weeks') {
dateLargestUnit = largestUnit;
}

let { years, months, weeks, days } = ES.DifferenceDate(other, { year, month, day }, dateLargestUnit);

let days;
({ days, hours, minutes, seconds, milliseconds, microseconds, nanoseconds } = ES.BalanceDuration(
days,
hours,
Expand Down
19 changes: 7 additions & 12 deletions polyfill/lib/yearmonth.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -102,18 +102,13 @@ export class YearMonth {
const largestUnit = ES.ToLargestTemporalUnit(options, 'years', ['weeks', 'days', 'hours', 'minutes', 'seconds']);
const comparison = YearMonth.compare(this, other);
if (comparison < 0) throw new RangeError('other instance cannot be larger than `this`');
let years = this.year - other.year;
let months = this.month - other.month;
if (months < 0) {
years -= 1;
months += 12;
}
if (largestUnit === 'months') {
months += 12 * years;
years = 0;
}
const Duration = GetIntrinsic('%Temporal.Duration%');
return new Duration(years, months);

const smallerFields = ES.ToTemporalYearMonthRecord(other);
const largerFields = ES.ToTemporalYearMonthRecord(this);
const TemporalDate = GetIntrinsic('%Temporal.Date%');
const smaller = calendar.dateFromFields({ ...smallerFields, day: 1 }, {}, TemporalDate);
const larger = calendar.dateFromFields({ ...largerFields, day: 1 }, {}, TemporalDate);
return calendar.difference(smaller, larger, { ...options, largestUnit });
}
equals(other) {
if (!ES.IsTemporalYearMonth(this)) throw new TypeError('invalid receiver');
Expand Down

0 comments on commit c589c47

Please sign in to comment.