javascript - Airbnb react-dates calendar with non-English locale - Stack Overflow

I am trying to use airbnb react-dates with non-English locale (Persian) and everything is working fine,

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.

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.

Share Improve this question edited Feb 5, 2018 at 9:30 Vikas Yadav 3,3542 gold badges23 silver badges22 bronze badges asked Feb 3, 2018 at 8:37 Moji IzadmehrMoji Izadmehr 2,53415 silver badges19 bronze badges 1
  • 1 there is an open issue about this – Sagiv b.g Commented Feb 3, 2018 at 9:23
Add a ment  | 

2 Answers 2

Reset to default 3 +50

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:

  • github
  • npm

how to use:

  • import momentJalali from 'moment-jalaali'

  • in the constructor of the ponent 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.

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

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

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744895614a4599676.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信