Skip to content

refactor(multiple): re-add missing feedback #29803

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 1 commit into from
Sep 30, 2024
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -569,12 +569,12 @@ describe('DateFnsAdapter', () => {
).toBeGreaterThan(0);
});

it('should add milliseconds to a date', () => {
const amount = 1234567;
it('should add seconds to a date', () => {
const amount = 20;
const initial = new Date(2024, JAN, 1, 12, 34, 56);
const result = adapter.addMilliseconds(initial, amount);
const result = adapter.addSeconds(initial, amount);
expect(result).not.toBe(initial);
expect(result.getTime() - initial.getTime()).toBe(amount);
expect(result.getTime() - initial.getTime()).toBe(amount * 1000);
});
});

Expand Down
8 changes: 4 additions & 4 deletions src/material-date-fns-adapter/adapter/date-fns-adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import {
addYears,
addMonths,
addDays,
addMilliseconds,
addSeconds,
isValid,
isDate,
format,
Expand Down Expand Up @@ -262,7 +262,7 @@ export class DateFnsAdapter extends DateAdapter<Date, Locale> {
}
}

return set(this.clone(target), {hours, minutes, seconds});
return set(this.clone(target), {hours, minutes, seconds, milliseconds: 0});
}

override getHours(date: Date): number {
Expand All @@ -281,7 +281,7 @@ export class DateFnsAdapter extends DateAdapter<Date, Locale> {
return this.parse(value, parseFormat);
}

override addMilliseconds(date: Date, amount: number): Date {
return addMilliseconds(date, amount);
override addSeconds(date: Date, amount: number): Date {
return addSeconds(date, amount);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -679,12 +679,12 @@ describe('LuxonDateAdapter', () => {
).toBeGreaterThan(0);
});

it('should add milliseconds to a date', () => {
const amount = 1234567;
it('should add seconds to a date', () => {
const amount = 20;
const initial = DateTime.local(2024, JAN, 1, 12, 34, 56);
const result = adapter.addMilliseconds(initial, amount);
const result = adapter.addSeconds(initial, amount);
expect(result).not.toBe(initial);
expect(result.toMillis() - initial.toMillis()).toBe(amount);
expect(result.toMillis() - initial.toMillis()).toBe(amount * 1000);
});
});

Expand Down
5 changes: 3 additions & 2 deletions src/material-luxon-adapter/adapter/luxon-date-adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,7 @@ export class LuxonDateAdapter extends DateAdapter<LuxonDateTime> {
hour: hours,
minute: minutes,
second: seconds,
millisecond: 0,
});
}

Expand Down Expand Up @@ -323,8 +324,8 @@ export class LuxonDateAdapter extends DateAdapter<LuxonDateTime> {
return result;
}

override addMilliseconds(date: LuxonDateTime, amount: number): LuxonDateTime {
return date.reconfigure(this._getOptions()).plus({milliseconds: amount});
override addSeconds(date: LuxonDateTime, amount: number): LuxonDateTime {
return date.reconfigure(this._getOptions()).plus({seconds: amount});
}

/** Gets the options that should be used when constructing a new `DateTime` object. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -660,11 +660,11 @@ describe('MomentDateAdapter', () => {
});

it('should add milliseconds to a date', () => {
const amount = 1234567;
const amount = 20;
const initial = moment([2024, JAN, 1, 12, 34, 56]);
const result = adapter.addMilliseconds(initial, amount);
const result = adapter.addSeconds(initial, amount);
expect(result).not.toBe(initial);
expect(result.valueOf() - initial.valueOf()).toBe(amount);
expect(result.valueOf() - initial.valueOf()).toBe(amount * 1000);
});
});

Expand Down
6 changes: 3 additions & 3 deletions src/material-moment-adapter/adapter/moment-date-adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ export class MomentDateAdapter extends DateAdapter<Moment> {
}
}

return this.clone(target).set({hours, minutes, seconds});
return this.clone(target).set({hours, minutes, seconds, milliseconds: 0});
}

override getHours(date: Moment): number {
Expand All @@ -285,8 +285,8 @@ export class MomentDateAdapter extends DateAdapter<Moment> {
return this.parse(value, parseFormat);
}

override addMilliseconds(date: Moment, amount: number): Moment {
return this.clone(date).add({milliseconds: amount});
override addSeconds(date: Moment, amount: number): Moment {
return this.clone(date).add({seconds: amount});
}

/** Creates a Moment instance while respecting the current UTC settings. */
Expand Down
8 changes: 4 additions & 4 deletions src/material/core/datetime/date-adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -243,11 +243,11 @@ export abstract class DateAdapter<D, L = any> {
}

/**
* Adds an amount of milliseconds to the specified date.
* @param date Date to which to add the milliseconds.
* @param amount Amount of milliseconds to add to the date.
* Adds an amount of seconds to the specified date.
* @param date Date to which to add the seconds.
* @param amount Amount of seconds to add to the date.
*/
addMilliseconds(date: D, amount: number): D {
addSeconds(date: D, amount: number): D {
throw new Error(NOT_IMPLEMENTED);
}

Expand Down
8 changes: 4 additions & 4 deletions src/material/core/datetime/native-date-adapter.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -625,12 +625,12 @@ describe('NativeDateAdapter', () => {
).toBeGreaterThan(0);
});

it('should add milliseconds to a date', () => {
const amount = 1234567;
it('should add seconds to a date', () => {
const amount = 20;
const initial = new Date(2024, JAN, 1, 12, 34, 56);
const result = adapter.addMilliseconds(initial, amount);
const result = adapter.addSeconds(initial, amount);
expect(result).not.toBe(initial);
expect(result.getTime() - initial.getTime()).toBe(amount);
expect(result.getTime() - initial.getTime()).toBe(amount * 1000);
});
});

Expand Down
4 changes: 2 additions & 2 deletions src/material/core/datetime/native-date-adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -355,8 +355,8 @@ export class NativeDateAdapter extends DateAdapter<Date> {
return this.invalid();
}

override addMilliseconds(date: Date, amount: number): Date {
return new Date(date.getTime() + amount);
override addSeconds(date: Date, amount: number): Date {
return new Date(date.getTime() + amount * 1000);
}

/** Creates a date but allows the month and date to overflow. */
Expand Down
4 changes: 2 additions & 2 deletions tools/public_api_guard/material/core.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export abstract class DateAdapter<D, L = any> {
abstract addCalendarDays(date: D, days: number): D;
abstract addCalendarMonths(date: D, months: number): D;
abstract addCalendarYears(date: D, years: number): D;
addMilliseconds(date: D, amount: number): D;
addSeconds(date: D, amount: number): D;
clampDate(date: D, min?: D | null, max?: D | null): D;
abstract clone(date: D): D;
compareDate(first: D, second: D): number;
Expand Down Expand Up @@ -409,7 +409,7 @@ export class NativeDateAdapter extends DateAdapter<Date> {
// (undocumented)
addCalendarYears(date: Date, years: number): Date;
// (undocumented)
addMilliseconds(date: Date, amount: number): Date;
addSeconds(date: Date, amount: number): Date;
// (undocumented)
clone(date: Date): Date;
// (undocumented)
Expand Down
Loading