react-dates icon indicating copy to clipboard operation
react-dates copied to clipboard

months are starting based on gregorian calendar

Open shahneh opened this issue 8 years ago • 8 comments

image today is the 17th day of month in Persian calendar but the 17th is showing at the 9th position because it's October 9 in Gregorian calendar

shahneh avatar Oct 09 '17 08:10 shahneh

I think this is because we are still using moment instead of moment-jalali to generate the table of dates - https://github.com/airbnb/react-dates/blob/master/src/utils/getCalendarMonthWeeks.js. We would have to figure out a way to plug in a different moment in that helper code.

majapw avatar Oct 09 '17 19:10 majapw

Could you solve this issue ?

FareheSoheil avatar Jul 29 '18 09:07 FareheSoheil

@FareheSoheil a PR is welcome.

ljharb avatar Jul 29 '18 20:07 ljharb

hi do you have a plan to solve this issue in future versions? thanks

hamidpouladi avatar Dec 10 '18 09:12 hamidpouladi

I worked on this issue, here is my branch. But I'm not sure that it is universal and clear solution. It just more difficult then just change something in https://github.com/airbnb/react-dates/blob/master/src/utils/getCalendarMonthWeeks.js, that @majapw adviced. There couple of changing in some other functions. And API for this purpose is not perfect:

moment.locale('fa');
...
<SingleDatePickerWrapper
        placeholder="تقویم فارسی"
        // You need to redefine initialVisibleMonth with momentJalaali
        initialVisibleMonth={() => momentJalaali(moment())}
        renderMonthText={month => momentJalaali(month).format('jMMMM jYYYY')}
        renderDayContents={day => momentJalaali(day).format('jD')}
        // You need to pass this prop to support Persian Calendar - it is used in utils functions
        // For example: getCalendarMonthWeeks: const firstOfMonth = month.clone().startOf(monthUnit).hour(12);
        monthUnit="jMonth"
        renderCalendarDay={({
          day, month, isOutsideDay, ...props
        }) => (
          <CalendarDay
            day={day}
            {...props}
            // Also You need to redefine isOutsideDay logic here with momentJalaali
            isOutsideDay={
                        !day || day.jMonth() !== momentJalaali(month).jMonth()
                    }
          />
        )}
      />

And you will get something like this: Persian

mmarkelov avatar Jul 09 '19 07:07 mmarkelov

@mmarkelov thanks my friend

hamidpouladi avatar Jul 09 '19 18:07 hamidpouladi

I have created a fork to fix this. calendarSystem prop added toDateRangePicker andSingleDatePicker components for supporting JALALI calendar system.

You can see a working range picker here:

https://mohsensaremi.github.io/react-dates/?path=/story/daterangepicker-drp--non-english-locale-persian

mohsensaremi avatar Dec 10 '20 15:12 mohsensaremi

@mmarkelov Hi, how can I import your branch in my project? Is it possible to use npm command to import it? Thanks.

mrafei avatar Nov 01 '21 05:11 mrafei