Skip to content

Commit 6a73684

Browse files
committed
feat(RelativeDateField): add roundUp prop
1 parent e252c31 commit 6a73684

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

src/components/RelativeDateField/hooks/useRelativeDateFieldState.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ export interface RelativeDateFieldState {
3333

3434
export interface RelativeDateFieldOptions extends ValueBase<string | null>, InputBase, Validation {
3535
timeZone?: string;
36+
/** Round up parsed date to the nearest granularity. */
37+
roundUp?: boolean;
3638
}
3739
export function useRelativeDateFieldState(props: RelativeDateFieldOptions): RelativeDateFieldState {
3840
const [value, setValue] = useControlledState(
@@ -67,7 +69,7 @@ export function useRelativeDateFieldState(props: RelativeDateFieldOptions): Rela
6769
if (!value) {
6870
return null;
6971
}
70-
return dateTimeParse(value, {timeZone: props.timeZone}) ?? null;
72+
return dateTimeParse(value, {timeZone: props.timeZone, roundUp: props.roundUp}) ?? null;
7173
}, [value, props.timeZone]);
7274

7375
const [lastCorrectDate, setLastCorrectDate] = React.useState(parsedDate);

src/components/RelativeDatePicker/hooks/useRelativeDatePickerState.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,10 @@ export type Value =
2121

2222
export type RelativeDatePickerMode = Value['type'];
2323

24-
export interface RelativeDatePickerStateOptions extends DateFieldBase<Value> {}
24+
export interface RelativeDatePickerStateOptions extends DateFieldBase<Value> {
25+
/** Round up parsed date to the nearest granularity. */
26+
roundUp?: boolean;
27+
}
2528

2629
export interface RelativeDatePickerState {
2730
value: Value | null;
@@ -114,6 +117,7 @@ export function useRelativeDatePickerState(
114117
disabled: props.disabled,
115118
readOnly: props.readOnly,
116119
timeZone: datePickerState.timeZone,
120+
roundUp: props.roundUp,
117121
});
118122

119123
if (!value) {

0 commit comments

Comments
 (0)