Skip to content

Commit

Permalink
Adds support to pass custom function to replace getNow in generateCon…
Browse files Browse the repository at this point in the history
…fig. (#9)

* Added getNow to the PickerProps type definition.

* Replaces the getNow in the generateConfig with the getNow from props if present to fix the timezone issues.
  • Loading branch information
deepakjosp authored Nov 1, 2024
1 parent 0fdd633 commit 024269c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/PickerInput/SinglePicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,9 @@ export interface BasePickerProps<DateType extends object = any>

export interface PickerProps<DateType extends object = any>
extends BasePickerProps<DateType>,
Omit<SharedTimeProps<DateType>, 'format' | 'defaultValue'> {}
Omit<SharedTimeProps<DateType>, 'format' | 'defaultValue'> {
getNow?: () => string;
}

/** Internal usage. For cross function get same aligned props */
export type ReplacedPickerProps<DateType extends object = any> = {
Expand Down
5 changes: 5 additions & 0 deletions src/PickerInput/hooks/useFilledProps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ type PickedProps<DateType extends object = any> = Pick<
defaultValue?: any;
pickerValue?: any;
defaultPickerValue?: any;
getNow?: () => string;
};

type ExcludeBooleanType<T> = T extends boolean ? never : T;
Expand Down Expand Up @@ -161,6 +162,10 @@ export default function useFilledProps<
const filledProps = React.useMemo(
() => ({
...props,
generateConfig: {
...generateConfig,
getNow: props.getNow || props.generateConfig.getNow,
},
prefixCls,
locale: mergedLocale,
picker,
Expand Down

0 comments on commit 024269c

Please sign in to comment.