calidy-com / dayjs-calendarsystems

Day.js Calendar Systems Plugin : extends Day.js library to allow the use of non-gregorian calendar systems.
Other
16 stars 3 forks source link

[Question]: How to check which calendar system used? #1

Closed mohamedsabil83 closed 6 months ago

mohamedsabil83 commented 6 months ago

Hello there. I'm working on a project using your package. I have a method that will get a Gregory or Hijri instance of Dayjs. How can I check which calendar system is used in that instance?

amirhmoradi commented 6 months ago

Hi @mohamedsabil83 , thanks for using the plugin. Dayjs has a property which stores the calendar system, and I used the same property to manage calendar systems and their conversion.

You can use the $C value of a given dayjs instance to check for the calendar system.

// ...code to import and init and extend dayjs

const dt = dayjs("2023-05-14");
const myDate = dt.toCalendarSystem("persian");

const myDateCalendarSystem = myDate.$C;

I will close this issue, please comment with more details and info if you believe this shall be kept open.

Best regards.

mohamedsabil83 commented 6 months ago

Hi @amirhmoradi; thanks for confirming that. After posting my question, I dug deeper and found the $C value and started using it until you replied to be sure if that's the right way or if there is a better or corrected way. Thanks again for the great package.