Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error: Invalid Jalali year -100721 on NextJS #12

Open
nafasebra opened this issue May 5, 2023 · 1 comment
Open

Error: Invalid Jalali year -100721 on NextJS #12

nafasebra opened this issue May 5, 2023 · 1 comment

Comments

@nafasebra
Copy link

nafasebra commented May 5, 2023

I got this error when app is mounted

Capture

and this is my component:

<Datepicker 
  input={
    <Field
      label="تاریخ رفت"
      id="date"
      name="date"
    />
  } 
  modeTheme={'light'}
  theme={'blue'}
  closeWhenSelectADay={true} // boolean
  defaultValue={moment()}
  value={dateInput}
  onChange={(val) => setDateInput(val)}
/>

Are you have any suggestion for solve the problem? what i to do?

@navidmadannezhad
Copy link

navidmadannezhad commented Jan 4, 2025

Hi Nafas, I also encountered the issue you've dealt with. Maybe you have solved it until now, but for whoever may encounter this in future, this is my working example:

const DateInput = (props: DatepickerProps) => {
    const todayDate = new Intl.DateTimeFormat('en-CA', {
        year: 'numeric',
        month: '2-digit',
        day: '2-digit',
    }).format(new Date()).replace(/-/g, '/');
    const [date, setDate] = useState<string>(props.value ?? todayDate);

    useEffect(() => {
        props.onChange(date);
    }, [date])

    return(
        <div>
            <Datepicker
                lang="fa"
                footer={(moment, setValue) => {
                    return (
                        <>
                            <div
                                onClick={() => {
                                    if (setValue) setValue(moment());
                                }}
                            >
                            برو به امروز
                            </div>
                        </>
                    );
                }}
                closeWhenSelectADay={true}
                disabled={false}
                format={'YYYY-MM-DD'}
                input={<SimpleInput placeholder="انتخاب تاریخ" />}
                loading={false}
                modeTheme={'light'}
                theme={'red'}
                value={date}
                adjustPosition={'auto'}
                onChange={(val: any) => {
                    // passes miladi
                    setDate(val?.format('YYYY/MM/DD') ?? "");
                }}
            />
        </div>
    )
}

Pay attention that you must set the value prop as gregorian, like "2022/11/02", the Datepicker component automatically converts it to shamsi date. Also do not forget to set the lang prop to "fa".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants