Skip to content

Commit 625082c

Browse files
authored
refactor(multiple): re-add missing feedback (angular#29803)
Makes the changes that came up during the code review of angular#29799, but weren't pushed to the branch by accident.
1 parent 6a8c73d commit 625082c

File tree

10 files changed

+33
-32
lines changed

10 files changed

+33
-32
lines changed

src/material-date-fns-adapter/adapter/date-fns-adapter.spec.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -569,12 +569,12 @@ describe('DateFnsAdapter', () => {
569569
).toBeGreaterThan(0);
570570
});
571571

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

src/material-date-fns-adapter/adapter/date-fns-adapter.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import {
2323
addYears,
2424
addMonths,
2525
addDays,
26-
addMilliseconds,
26+
addSeconds,
2727
isValid,
2828
isDate,
2929
format,
@@ -262,7 +262,7 @@ export class DateFnsAdapter extends DateAdapter<Date, Locale> {
262262
}
263263
}
264264

265-
return set(this.clone(target), {hours, minutes, seconds});
265+
return set(this.clone(target), {hours, minutes, seconds, milliseconds: 0});
266266
}
267267

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

284-
override addMilliseconds(date: Date, amount: number): Date {
285-
return addMilliseconds(date, amount);
284+
override addSeconds(date: Date, amount: number): Date {
285+
return addSeconds(date, amount);
286286
}
287287
}

src/material-luxon-adapter/adapter/luxon-date-adapter.spec.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -679,12 +679,12 @@ describe('LuxonDateAdapter', () => {
679679
).toBeGreaterThan(0);
680680
});
681681

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

src/material-luxon-adapter/adapter/luxon-date-adapter.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,7 @@ export class LuxonDateAdapter extends DateAdapter<LuxonDateTime> {
296296
hour: hours,
297297
minute: minutes,
298298
second: seconds,
299+
millisecond: 0,
299300
});
300301
}
301302

@@ -323,8 +324,8 @@ export class LuxonDateAdapter extends DateAdapter<LuxonDateTime> {
323324
return result;
324325
}
325326

326-
override addMilliseconds(date: LuxonDateTime, amount: number): LuxonDateTime {
327-
return date.reconfigure(this._getOptions()).plus({milliseconds: amount});
327+
override addSeconds(date: LuxonDateTime, amount: number): LuxonDateTime {
328+
return date.reconfigure(this._getOptions()).plus({seconds: amount});
328329
}
329330

330331
/** Gets the options that should be used when constructing a new `DateTime` object. */

src/material-moment-adapter/adapter/moment-date-adapter.spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -660,11 +660,11 @@ describe('MomentDateAdapter', () => {
660660
});
661661

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

src/material-moment-adapter/adapter/moment-date-adapter.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ export class MomentDateAdapter extends DateAdapter<Moment> {
266266
}
267267
}
268268

269-
return this.clone(target).set({hours, minutes, seconds});
269+
return this.clone(target).set({hours, minutes, seconds, milliseconds: 0});
270270
}
271271

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

288-
override addMilliseconds(date: Moment, amount: number): Moment {
289-
return this.clone(date).add({milliseconds: amount});
288+
override addSeconds(date: Moment, amount: number): Moment {
289+
return this.clone(date).add({seconds: amount});
290290
}
291291

292292
/** Creates a Moment instance while respecting the current UTC settings. */

src/material/core/datetime/date-adapter.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -243,11 +243,11 @@ export abstract class DateAdapter<D, L = any> {
243243
}
244244

245245
/**
246-
* Adds an amount of milliseconds to the specified date.
247-
* @param date Date to which to add the milliseconds.
248-
* @param amount Amount of milliseconds to add to the date.
246+
* Adds an amount of seconds to the specified date.
247+
* @param date Date to which to add the seconds.
248+
* @param amount Amount of seconds to add to the date.
249249
*/
250-
addMilliseconds(date: D, amount: number): D {
250+
addSeconds(date: D, amount: number): D {
251251
throw new Error(NOT_IMPLEMENTED);
252252
}
253253

src/material/core/datetime/native-date-adapter.spec.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -625,12 +625,12 @@ describe('NativeDateAdapter', () => {
625625
).toBeGreaterThan(0);
626626
});
627627

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

src/material/core/datetime/native-date-adapter.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -355,8 +355,8 @@ export class NativeDateAdapter extends DateAdapter<Date> {
355355
return this.invalid();
356356
}
357357

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

362362
/** Creates a date but allows the month and date to overflow. */

tools/public_api_guard/material/core.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ export abstract class DateAdapter<D, L = any> {
5959
abstract addCalendarDays(date: D, days: number): D;
6060
abstract addCalendarMonths(date: D, months: number): D;
6161
abstract addCalendarYears(date: D, years: number): D;
62-
addMilliseconds(date: D, amount: number): D;
62+
addSeconds(date: D, amount: number): D;
6363
clampDate(date: D, min?: D | null, max?: D | null): D;
6464
abstract clone(date: D): D;
6565
compareDate(first: D, second: D): number;
@@ -409,7 +409,7 @@ export class NativeDateAdapter extends DateAdapter<Date> {
409409
// (undocumented)
410410
addCalendarYears(date: Date, years: number): Date;
411411
// (undocumented)
412-
addMilliseconds(date: Date, amount: number): Date;
412+
addSeconds(date: Date, amount: number): Date;
413413
// (undocumented)
414414
clone(date: Date): Date;
415415
// (undocumented)

0 commit comments

Comments
 (0)