Skip to content

Commit

Permalink
fix: types
Browse files Browse the repository at this point in the history
  • Loading branch information
logaretm committed Feb 8, 2025
1 parent 73ccfcf commit e5f4cc0
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 8 deletions.
10 changes: 5 additions & 5 deletions packages/core/src/useDateTimeField/temporalPartial.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,29 @@ import { CalendarIdentifier } from '../useCalendar';
import { isObject } from '../../../shared/src';

export function createTemporalPartial(calendar: CalendarIdentifier, timeZone: string) {
const zonedDateTime = Temporal.Now.zonedDateTime(calendar, timeZone);
const zonedDateTime = Temporal.Now.zonedDateTime(calendar, timeZone) as TemporalPartial;
zonedDateTime['~fw_temporal_partial'] = {};

return zonedDateTime as TemporalPartial;
return zonedDateTime;
}

export function toTemporalPartial(
value: Temporal.ZonedDateTime | TemporalPartial,
setParts?: DateTimeSegmentType[],
): TemporalPartial {
const clone = Temporal.ZonedDateTime.from(value);
const clone = Temporal.ZonedDateTime.from(value) as TemporalPartial;
clone['~fw_temporal_partial'] = isTemporalPartial(value) ? value['~fw_temporal_partial'] : {};
if (setParts) {
setParts.forEach(part => {
clone['~fw_temporal_partial'][part] = true;
});
}

return clone as TemporalPartial;
return clone;
}

export function isTemporalPartial(value: Temporal.ZonedDateTime): value is TemporalPartial {
return isObject(value['~fw_temporal_partial']);
return isObject((value as TemporalPartial)['~fw_temporal_partial']);
}

export function isTemporalPartSet(value: TemporalPartial, part: DateTimeSegmentType): boolean {
Expand Down
1 change: 0 additions & 1 deletion packages/core/src/useDateTimeField/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,4 @@ export type TemporalPartial = Temporal.ZonedDateTime & {
[`~fw_temporal_partial`]: {
[key: string]: boolean | undefined;
};
[`~fw_temporal_full_partial`]?: true;
};
4 changes: 2 additions & 2 deletions packages/core/src/useDateTimeField/useDateTimeSegmentGroup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ function useDateArithmetic({ currentDate }: ArithmeticInit) {
});

if (isTemporalPartial(date)) {
newDate['~fw_temporal_partial'] = {
(newDate as TemporalPartial)['~fw_temporal_partial'] = {
...date['~fw_temporal_partial'],
[part]: true,
};
Expand Down Expand Up @@ -334,7 +334,7 @@ function useDateArithmetic({ currentDate }: ArithmeticInit) {
});
}

newDate['~fw_temporal_partial'] = {
(newDate as TemporalPartial)['~fw_temporal_partial'] = {
...date['~fw_temporal_partial'],
[part]: true,
};
Expand Down

0 comments on commit e5f4cc0

Please sign in to comment.