Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/Picker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
};

Expand Down
4 changes: 2 additions & 2 deletions lib/PickerInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down