Skip to content

Commit 27bed18

Browse files
fix: Fix linting issues
1 parent af7884d commit 27bed18

File tree

3 files changed

+35
-34
lines changed

3 files changed

+35
-34
lines changed

packages/@internationalized/date/src/CalendarDate.ts

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,8 @@ export class CalendarDate {
9494
}
9595

9696
/** Returns a new `CalendarDate` with the given fields set to the provided values. Other fields will be constrained accordingly. */
97-
set(fields: DateFields): CalendarDate {
98-
return set(this, fields);
97+
set(fields: DateFields, ignoreDay?: boolean): CalendarDate {
98+
return set(this, fields, ignoreDay);
9999
}
100100

101101
/**
@@ -165,8 +165,8 @@ export class Time {
165165
}
166166

167167
/** Returns a new `Time` with the given fields set to the provided values. Other fields will be constrained accordingly. */
168-
set(fields: TimeFields): Time {
169-
return setTime(this, fields);
168+
set(fields: TimeFields, ignoreDay?: boolean): Time {
169+
return setTime(this, fields, ignoreDay);
170170
}
171171

172172
/**
@@ -264,13 +264,13 @@ export class CalendarDateTime {
264264
* Returns a new `CalendarDateTime` with the given field adjusted by a specified amount.
265265
* When the resulting value reaches the limits of the field, it wraps around.
266266
*/
267-
cycle(field: DateField | TimeField, amount: number, options?: CycleTimeOptions): CalendarDateTime {
267+
cycle(field: DateField | TimeField, amount: number, options?: CycleTimeOptions, ignoreDay?: boolean): CalendarDateTime {
268268
switch (field) {
269269
case 'era':
270270
case 'year':
271271
case 'month':
272272
case 'day':
273-
return cycleDate(this, field, amount, options);
273+
return cycleDate(this, field, amount, options, ignoreDay);
274274
default:
275275
return cycleTime(this, field, amount, options);
276276
}
@@ -329,10 +329,10 @@ export class ZonedDateTime {
329329
/** The UTC offset for this time, in milliseconds. */
330330
public readonly offset: number;
331331

332-
constructor(year: number, month: number, day: number, timeZone: string, offset: number, hour?: number, minute?: number, second?: number, millisecond?: number);
333-
constructor(era: string, year: number, month: number, day: number, timeZone: string, offset: number, hour?: number, minute?: number, second?: number, millisecond?: number);
334-
constructor(calendar: Calendar, year: number, month: number, day: number, timeZone: string, offset: number, hour?: number, minute?: number, second?: number, millisecond?: number);
335-
constructor(calendar: Calendar, era: string, year: number, month: number, day: number, timeZone: string, offset: number, hour?: number, minute?: number, second?: number, millisecond?: number);
332+
constructor(year: number, month: number, day: number, timeZone: string, offset: number, hour?: number, minute?: number, second?: number, millisecond?: number, ignoreDay?: boolean);
333+
constructor(era: string, year: number, month: number, day: number, timeZone: string, offset: number, hour?: number, minute?: number, second?: number, millisecond?: number, ignoreDay?: boolean);
334+
constructor(calendar: Calendar, year: number, month: number, day: number, timeZone: string, offset: number, hour?: number, minute?: number, second?: number, millisecond?: number, ignoreDay?: boolean);
335+
constructor(calendar: Calendar, era: string, year: number, month: number, day: number, timeZone: string, offset: number, hour?: number, minute?: number, second?: number, millisecond?: number, ignoreDay?: boolean);
336336
constructor(...args: any[]) {
337337
let [calendar, era, year, month, day] = shiftArgs(args);
338338
let timeZone = args.shift();
@@ -348,16 +348,17 @@ export class ZonedDateTime {
348348
this.minute = args.shift() || 0;
349349
this.second = args.shift() || 0;
350350
this.millisecond = args.shift() || 0;
351+
const ignoreDay = args.shift() || 0;
351352

352-
constrain(this);
353+
constrain(this, ignoreDay);
353354
}
354355

355356
/** Returns a copy of this date. */
356-
copy(): ZonedDateTime {
357+
copy(ignoreDay?: boolean): ZonedDateTime {
357358
if (this.era) {
358-
return new ZonedDateTime(this.calendar, this.era, this.year, this.month, this.day, this.timeZone, this.offset, this.hour, this.minute, this.second, this.millisecond);
359+
return new ZonedDateTime(this.calendar, this.era, this.year, this.month, this.day, this.timeZone, this.offset, this.hour, this.minute, this.second, this.millisecond, ignoreDay);
359360
} else {
360-
return new ZonedDateTime(this.calendar, this.year, this.month, this.day, this.timeZone, this.offset, this.hour, this.minute, this.second, this.millisecond);
361+
return new ZonedDateTime(this.calendar, this.year, this.month, this.day, this.timeZone, this.offset, this.hour, this.minute, this.second, this.millisecond, ignoreDay);
361362
}
362363
}
363364

@@ -372,16 +373,16 @@ export class ZonedDateTime {
372373
}
373374

374375
/** Returns a new `ZonedDateTime` with the given fields set to the provided values. Other fields will be constrained accordingly. */
375-
set(fields: DateFields & TimeFields, disambiguation?: Disambiguation): ZonedDateTime {
376-
return setZoned(this, fields, disambiguation);
376+
set(fields: DateFields & TimeFields, disambiguation?: Disambiguation, ignoreDay?: boolean): ZonedDateTime {
377+
return setZoned(this, fields, disambiguation, ignoreDay);
377378
}
378379

379380
/**
380381
* Returns a new `ZonedDateTime` with the given field adjusted by a specified amount.
381382
* When the resulting value reaches the limits of the field, it wraps around.
382383
*/
383-
cycle(field: DateField | TimeField, amount: number, options?: CycleTimeOptions): ZonedDateTime {
384-
return cycleZoned(this, field, amount, options);
384+
cycle(field: DateField | TimeField, amount: number, options?: CycleTimeOptions, ignoreDay?: boolean): ZonedDateTime {
385+
return cycleZoned(this, field, amount, options, ignoreDay);
385386
}
386387

387388
/** Converts the date to a native JavaScript Date object. */

packages/@internationalized/date/src/manipulation.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -173,10 +173,10 @@ export function set(date: CalendarDate | CalendarDateTime, fields: DateFields, i
173173
return mutableDate;
174174
}
175175

176-
export function setTime(value: CalendarDateTime, fields: TimeFields): CalendarDateTime;
177-
export function setTime(value: Time, fields: TimeFields): Time;
178-
export function setTime(value: Time | CalendarDateTime, fields: TimeFields): Mutable<Time | CalendarDateTime> {
179-
let mutableValue: Mutable<Time | CalendarDateTime> = value.copy();
176+
export function setTime(value: CalendarDateTime, fields: TimeFields, ignoreDay?: boolean): CalendarDateTime;
177+
export function setTime(value: Time, fields: TimeFields, ignoreDay?: boolean): Time;
178+
export function setTime(value: Time | CalendarDateTime, fields: TimeFields, ignoreDay?: boolean): Mutable<Time | CalendarDateTime> {
179+
let mutableValue: Mutable<Time | CalendarDateTime> = value.copy(ignoreDay);
180180

181181
if (fields.hour != null) {
182182
mutableValue.hour = fields.hour;
@@ -404,7 +404,7 @@ export function subtractZoned(dateTime: ZonedDateTime, duration: DateTimeDuratio
404404
return addZoned(dateTime, invertDuration(duration));
405405
}
406406

407-
export function cycleZoned(dateTime: ZonedDateTime, field: DateField | TimeField, amount: number, options?: CycleTimeOptions): ZonedDateTime {
407+
export function cycleZoned(dateTime: ZonedDateTime, field: DateField | TimeField, amount: number, options?: CycleTimeOptions, ignoreDay?: boolean): ZonedDateTime {
408408
// For date fields, we want the time to remain consistent and the UTC offset to potentially change to account for DST changes.
409409
// For time fields, we want the time to change by the amount given. This may result in the hour field staying the same, but the UTC
410410
// offset changing in the case of a backward DST transition, or skipping an hour in the case of a forward DST transition.
@@ -458,7 +458,7 @@ export function cycleZoned(dateTime: ZonedDateTime, field: DateField | TimeField
458458
case 'year':
459459
case 'month':
460460
case 'day': {
461-
let res = cycleDate(toCalendarDateTime(dateTime), field, amount, options);
461+
let res = cycleDate(toCalendarDateTime(dateTime), field, amount, options, ignoreDay);
462462
let ms = toAbsolute(res, dateTime.timeZone);
463463
return toCalendar(fromAbsolute(ms, dateTime.timeZone), dateTime.calendar);
464464
}
@@ -467,11 +467,11 @@ export function cycleZoned(dateTime: ZonedDateTime, field: DateField | TimeField
467467
}
468468
}
469469

470-
export function setZoned(dateTime: ZonedDateTime, fields: DateFields & TimeFields, disambiguation?: Disambiguation): ZonedDateTime {
470+
export function setZoned(dateTime: ZonedDateTime, fields: DateFields & TimeFields, disambiguation?: Disambiguation, ignoreDay?: boolean): ZonedDateTime {
471471
// Set the date/time fields, and recompute the UTC offset to account for DST changes.
472472
// We also need to validate by converting back to a local time in case hours are skipped during forward DST transitions.
473473
let plainDateTime = toCalendarDateTime(dateTime);
474-
let res = setTime(set(plainDateTime, fields), fields);
474+
let res = setTime(set(plainDateTime, fields, ignoreDay), fields);
475475

476476
// If the resulting plain date time values are equal, return the original time.
477477
// We don't want to change the offset when setting the time to the same value.

packages/@react-stately/datepicker/src/useDateFieldState.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -455,14 +455,14 @@ export function useDateFieldState<T extends DateValue = DateValue>(props: DateFi
455455
let isPM = displayValue.hour >= 12;
456456
let shouldBePM = placeholder.hour >= 12;
457457
if (isPM && !shouldBePM) {
458-
value = displayValue.set({hour: displayValue.hour - 12}, true);
458+
value = displayValue.set({hour: displayValue.hour - 12}, undefined, true);
459459
} else if (!isPM && shouldBePM) {
460-
value = displayValue.set({hour: displayValue.hour + 12}, true);
460+
value = displayValue.set({hour: displayValue.hour + 12}, undefined, true);
461461
}
462462
} else if (part === 'hour' && 'hour' in displayValue && displayValue.hour >= 12 && validSegments.dayPeriod) {
463-
value = displayValue.set({hour: placeholder['hour'] + 12}, true);
463+
value = displayValue.set({hour: placeholder['hour'] + 12}, undefined, true);
464464
} else if (part in displayValue) {
465-
value = displayValue.set({[part]: placeholder[part]}, true);
465+
value = displayValue.set({[part]: placeholder[part]}, undefined, true);
466466
}
467467
updatePlaceholder(value);
468468
},
@@ -652,7 +652,7 @@ function addSegment(value: DateValue, part: string, amount: number, options: Int
652652
case 'dayPeriod': {
653653
let hours = value.hour;
654654
let isPM = hours >= 12;
655-
return value.set({hour: isPM ? hours - 12 : hours + 12}, true);
655+
return value.set({hour: isPM ? hours - 12 : hours + 12}, undefined, true);
656656
}
657657
case 'hour':
658658
case 'minute':
@@ -673,7 +673,7 @@ function setSegment(value: DateValue, part: string, segmentValue: number | strin
673673
case 'month':
674674
case 'year':
675675
case 'era':
676-
return value.set({[part]: segmentValue}, true);
676+
return value.set({[part]: segmentValue}, undefined, true);
677677
}
678678

679679
if ('hour' in value && typeof segmentValue === 'number') {
@@ -685,7 +685,7 @@ function setSegment(value: DateValue, part: string, segmentValue: number | strin
685685
if (isPM === wasPM) {
686686
return value;
687687
}
688-
return value.set({hour: wasPM ? hours - 12 : hours + 12}, true);
688+
return value.set({hour: wasPM ? hours - 12 : hours + 12}, undefined, true);
689689
}
690690
case 'hour':
691691
// In 12 hour time, ensure that AM/PM does not change
@@ -702,7 +702,7 @@ function setSegment(value: DateValue, part: string, segmentValue: number | strin
702702
// fallthrough
703703
case 'minute':
704704
case 'second':
705-
return value.set({[part]: segmentValue}, true);
705+
return value.set({[part]: segmentValue}, undefined, true);
706706
}
707707
}
708708

0 commit comments

Comments
 (0)