diff --git a/src/material-date-fns-adapter/adapter/date-fns-adapter.spec.ts b/src/material-date-fns-adapter/adapter/date-fns-adapter.spec.ts index dcdc466b2bf2..f1f684f64b78 100644 --- a/src/material-date-fns-adapter/adapter/date-fns-adapter.spec.ts +++ b/src/material-date-fns-adapter/adapter/date-fns-adapter.spec.ts @@ -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); }); }); diff --git a/src/material-date-fns-adapter/adapter/date-fns-adapter.ts b/src/material-date-fns-adapter/adapter/date-fns-adapter.ts index 0cef3728d8fc..29e3b9927c83 100644 --- a/src/material-date-fns-adapter/adapter/date-fns-adapter.ts +++ b/src/material-date-fns-adapter/adapter/date-fns-adapter.ts @@ -23,7 +23,7 @@ import { addYears, addMonths, addDays, - addMilliseconds, + addSeconds, isValid, isDate, format, @@ -262,7 +262,7 @@ export class DateFnsAdapter extends DateAdapter { } } - return set(this.clone(target), {hours, minutes, seconds}); + return set(this.clone(target), {hours, minutes, seconds, milliseconds: 0}); } override getHours(date: Date): number { @@ -281,7 +281,7 @@ export class DateFnsAdapter extends DateAdapter { 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); } } diff --git a/src/material-luxon-adapter/adapter/luxon-date-adapter.spec.ts b/src/material-luxon-adapter/adapter/luxon-date-adapter.spec.ts index 1b6f90e1c5ac..8ee0701ece03 100644 --- a/src/material-luxon-adapter/adapter/luxon-date-adapter.spec.ts +++ b/src/material-luxon-adapter/adapter/luxon-date-adapter.spec.ts @@ -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); }); }); diff --git a/src/material-luxon-adapter/adapter/luxon-date-adapter.ts b/src/material-luxon-adapter/adapter/luxon-date-adapter.ts index c647a825d92b..5e7ade456685 100644 --- a/src/material-luxon-adapter/adapter/luxon-date-adapter.ts +++ b/src/material-luxon-adapter/adapter/luxon-date-adapter.ts @@ -296,6 +296,7 @@ export class LuxonDateAdapter extends DateAdapter { hour: hours, minute: minutes, second: seconds, + millisecond: 0, }); } @@ -323,8 +324,8 @@ export class LuxonDateAdapter extends DateAdapter { 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. */ diff --git a/src/material-moment-adapter/adapter/moment-date-adapter.spec.ts b/src/material-moment-adapter/adapter/moment-date-adapter.spec.ts index 2238723d8efc..86cb41c12f59 100644 --- a/src/material-moment-adapter/adapter/moment-date-adapter.spec.ts +++ b/src/material-moment-adapter/adapter/moment-date-adapter.spec.ts @@ -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); }); }); diff --git a/src/material-moment-adapter/adapter/moment-date-adapter.ts b/src/material-moment-adapter/adapter/moment-date-adapter.ts index c4fe1e6d72ae..81105fb70a0b 100644 --- a/src/material-moment-adapter/adapter/moment-date-adapter.ts +++ b/src/material-moment-adapter/adapter/moment-date-adapter.ts @@ -266,7 +266,7 @@ export class MomentDateAdapter extends DateAdapter { } } - return this.clone(target).set({hours, minutes, seconds}); + return this.clone(target).set({hours, minutes, seconds, milliseconds: 0}); } override getHours(date: Moment): number { @@ -285,8 +285,8 @@ export class MomentDateAdapter extends DateAdapter { 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. */ diff --git a/src/material/core/datetime/date-adapter.ts b/src/material/core/datetime/date-adapter.ts index e3ad332e1807..08bb8be38078 100644 --- a/src/material/core/datetime/date-adapter.ts +++ b/src/material/core/datetime/date-adapter.ts @@ -243,11 +243,11 @@ export abstract class DateAdapter { } /** - * 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); } diff --git a/src/material/core/datetime/native-date-adapter.spec.ts b/src/material/core/datetime/native-date-adapter.spec.ts index a5112359b79f..cd1979274c2e 100644 --- a/src/material/core/datetime/native-date-adapter.spec.ts +++ b/src/material/core/datetime/native-date-adapter.spec.ts @@ -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); }); }); diff --git a/src/material/core/datetime/native-date-adapter.ts b/src/material/core/datetime/native-date-adapter.ts index 3b06966d817a..dff89e74e6de 100644 --- a/src/material/core/datetime/native-date-adapter.ts +++ b/src/material/core/datetime/native-date-adapter.ts @@ -355,8 +355,8 @@ export class NativeDateAdapter extends DateAdapter { 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. */ diff --git a/tools/public_api_guard/material/core.md b/tools/public_api_guard/material/core.md index abdc0028e14e..0314f9e075f4 100644 --- a/tools/public_api_guard/material/core.md +++ b/tools/public_api_guard/material/core.md @@ -59,7 +59,7 @@ export abstract class DateAdapter { 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; @@ -409,7 +409,7 @@ export class NativeDateAdapter extends DateAdapter { // (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)