diff --git a/lib/Picker.tsx b/lib/Picker.tsx index 61d497e..f0887a3 100644 --- a/lib/Picker.tsx +++ b/lib/Picker.tsx @@ -89,12 +89,12 @@ function Picker(originalProps: PickerProps, { slots }: SetupContext) { return format(date, fmt, { locale: locale.value.formatLocale }); }; - const parseDate = (value: string, fmt?: string): Date => { + const parseDate = (value: string, fmt?: string, defaultDate?: Date): Date => { fmt = fmt || props.format; if (isPlainObject(props.formatter) && typeof props.formatter.parse === 'function') { return props.formatter.parse(value, fmt); } - const backupDate = new Date(); + const backupDate = defaultDate || new Date(); return parse(value, fmt, { locale: locale.value.formatLocale, backupDate }); }; diff --git a/lib/PickerInput.tsx b/lib/PickerInput.tsx index c1c54f0..79cd50f 100644 --- a/lib/PickerInput.tsx +++ b/lib/PickerInput.tsx @@ -24,7 +24,7 @@ export interface PickerInputBaseProps { export interface PickerInputProps extends PickerInputBaseProps { value: Date | Date[]; formatDate: (v: Date) => string; - parseDate: (v: string) => Date; + parseDate: (v: string, fmt?: string, defaultDate?: Date) => Date; disabledDate: (v: Date) => boolean; onChange: (v: Date | Date[] | null | null[]) => void; onFocus: () => void; @@ -109,7 +109,7 @@ function PickerInput(originalProps: PickerInputProps, { slots }: SetupContext) { } else if (props.multiple) { date = text.split(innerSeparator.value).map((v) => props.parseDate(v.trim())); } else { - date = props.parseDate(text); + date = props.parseDate(text, undefined, props.value as Date); } if (isValidValue(date) && !isDisabledValue(date)) { props.onChange(date);