jalaliday icon indicating copy to clipboard operation
jalaliday copied to clipboard

multi extend problem

Open javadbat opened this issue 4 years ago • 3 comments

when I try to use jalaliday in a specific component I realize it converts my Jalali year 1399 to gregorian 3263 instead of 2020. as I check more I find out its a combination of webpack and your library problem. when someone import jalalidate in multiple modules in one special hierarchy and extend the original dayjs this library keep adding extra year in date convert process for example if I use this:

import dayjs from 'dayjs';
import jalaliday from 'jalaliday';
dayjs.extend(jalaliday);
dayjs.extend(jalaliday);
dayjs.extend(jalaliday);

the final result of dayjs(1399-08-08, { jalali: true }); will be 4505 as you add more extend it add 621 years to the resulting year 3263->3884->4505->.... i think there must be a solution that multiple extend won't result in wrong date convert

javadbat avatar Aug 31 '20 05:08 javadbat

i just fix it temporary by

if(typeof dayjs.isJalali == "function"){
    dayjs.extend(jalaliday);
}

javadbat avatar Aug 31 '20 06:08 javadbat

I have the same problem I had set calendar to 'jalali'

i fix the problem by:

if (!dayjs.calendar) { dayjs.extend(jalaliday); }

masoudelahi avatar Oct 26 '20 16:10 masoudelahi

I have the same problem I had set calendar to 'jalali'

i fix the problem by:

if (!dayjs.calendar) { dayjs.extend(jalaliday); }

Yes I did the same for my calendar component https://www.npmjs.com/package/jb-date-input

javadbat avatar Oct 26 '20 17:10 javadbat