mberneti / react-datepicker2

react datepicker component.(include persian jalaali calendar)
https://mberneti.github.io/react-datepicker2/
MIT License
234 stars 79 forks source link

Invalid jalali date while setting isGregorian as false! #36

Closed afsanefdaa closed 5 years ago

afsanefdaa commented 5 years ago

This is how I used this Datepicker :

<DatePicker
          inputJalaaliFormat="jYYYY-jMM-jDD"
          timePicker={timePicker}
          value={value}
          isGregorian={isGregorian}
          onChange={date => onChange(date)}
        />

When I change the date by clicking on the first page everything is fine! But after changing the year by the top arrows and change the month It throws this error! This happens when isGregorian as false but as soon as I change it into isGregorian as true it's no longer throws an error!

index.js:4749 Uncaught Error: Invalid Jalaali year -100721
    at jalCal (index.js:4749)
    at d2j (index.js:4813)
    at Object.toJalaali (index.js:4681)
    at toJalaali$1 (index.js:5784)
    at F.push../node_modules/react-datepicker2/dist/index.js.jMoment.fn.jMonth (index.js:5550)
    at F.jM (index.js:4970)
    at F.<anonymous> (index.js:5009)
    at Object.jMM (index.js:5176)
    at F.push../node_modules/react-datepicker2/dist/index.js.jMoment.fn.format (index.js:5506)
    at index.js:10766
    at Array.map (<anonymous>)
    at Calendar.renderDays (index.js:10765)
    at Calendar.render (index.js:10846)
    at finishClassComponent (react-dom.development.js:17039)
    at updateClassComponent (react-dom.development.js:16994)
    at beginWork$1 (react-dom.development.js:18505)
    at HTMLUnknownElement.callCallback (react-dom.development.js:347)
    at Object.invokeGuardedCallbackDev (react-dom.development.js:397)
    at invokeGuardedCallback (react-dom.development.js:454)
    at beginWork$$1 (react-dom.development.js:23217)
    at performUnitOfWork (react-dom.development.js:22208)
    at workLoopSync (react-dom.development.js:22185)
    at renderRoot (react-dom.development.js:21878)
    at runRootCallback (react-dom.development.js:21554)
    at react-dom.development.js:11353
    at unstable_runWithPriority (scheduler.development.js:643)
    at runWithPriority$2 (react-dom.development.js:11305)
    at flushSyncCallbackQueueImpl (react-dom.development.js:11349)
    at flushSyncCallbackQueue (react-dom.development.js:11338)
    at discreteUpdates$1 (react-dom.development.js:21677)
    at discreteUpdates (react-dom.development.js:2359)
    at dispatchDiscreteEvent (react-dom.development.js:5979)
savalanpour commented 5 years ago

Add in constructor method this line: moment.loadPersian({ dialect: 'persian-modern' });

for example

constructor(props) {
    super(props);
    moment.loadPersian({ dialect: 'persian-modern' });
    this.state = {
      value: moment('1396/7/6', 'jYYYY/jM/jD'),
    };
  }
aliakbarazizi commented 5 years ago

@afsanefda I think you should add this to document.