5

I am trying to use airbnb react-dates with non-English locale (Persian) and everything is working fine, except for the first day of the month.

The months do not start from the first day in Persian (Jalaali) calendar to the 30th day, they start from the 10th day of the month and continue to the 10th day of the next month.

This problem even exists in their example. I was wondering if there is any way to deal with this issue.

Vikas Yadav
  • 3,094
  • 2
  • 20
  • 21
Moji Izadmehr
  • 2,434
  • 13
  • 19

2 Answers2

3

I have been dealing with this issue in a project,this problem is currently an open issue in airbnb react-dates. In order to solve this, I have forked the original project so that it works with jalali moment and the months start from the correct day,the link to the github and npm repositories are:

how to use:

  • import momentJalali from 'moment-jalaali'

  • in the constructor of the component in which you want to use datepicker set the appropriate locale :

    momentJalali.locale('fa')

  • import the datepicker from the forked repository:

import {SingleDatePicker,DateRangePicker} from "react-dates-jalali";

  • in render section use the singdatepicker in the following way:

    <SingleDatePicker
          date={date} //momentDate if you have not set this property,it automatically sets to today
          focused={this.onFocusChange}//function change focused:open-close
          onFocusChange={.../function}
          showClearDate={true}
          required={true}
          isRTL={true}
          monthFormat={monthFormat}//for persian:'jMMMM jYYYY', for english :'MMMM YYYY'
          onDateChange={this.onDateChange}//function set your date Change
     />
    
  • in render section use the daterangepicker in the following way:

     <DateRangePicker
      startDate={startDate} //moment startDate if you have not set this property,it automatically sets to today
      endDate={endDate} //moment endDate
      onFocusChange={.../function}
      required={true}
      isRTL={true}
      onDatesChange={this.onDatesChange}//function set startDate and endDate
    focusedInput={focusedInput}//similar to airbnb api-open\close
    showClearDates={true}
      monthFormat={monthFormat}//for persian:'jMMMM jYYYY', for english :'MMMM YYYY'
       />
    

Needless to say,this repositories support all other airbnb react-dates apis which are not mentioned here.

You can also this repository if your site is multilingual and you can change the locale and month format whenever you want.

f.jafari
  • 568
  • 3
  • 10
  • Editions must be applied to the main lib. This lib is not using the latest version of react-dates, so its debugs are not applied. Moreover this react-dates-jalali had bug in onDatesChange handler, which returns a wrong date on selection and no documents have been pulbished about it. – mohammad eslahi sani Oct 02 '18 at 07:29
  • ok, I got it, I'm trying to fix it in the new version of Airbnb – f.jafari Apr 10 '19 at 11:48
3

I just imported moment and locale like this and it worked:

import moment from 'moment';
import 'moment/locale/pt-br';