jalaali / jalaali-js

JavaScript functions for converting Jalaali and Gregorian calendar systems to each other
MIT License
310 stars 36 forks source link

first/last of month #41

Open mmoghadam11 opened 2 years ago

mmoghadam11 commented 2 years ago

how can we detect the first or last day of a jalajy month ??? example : now = 1401/6/12 first of month : 1401/6/1

and how we can walk through days??

MR-Mostafa commented 2 years ago

If you wish to find the last day of the month of Jalali, you can use the following method.

jalaaliMonthLength

jalaali.jalaaliMonthLength(1394, 12) // 29
jalaali.jalaaliMonthLength(1395, 12) // 30

And to walking through the month:

const getLastDayOfMonth = parseInt(jalaali.jalaaliMonthLength(1401, 6), 10); // 31
const range = Array.from({ length: getLastDayOfMonth }, (_, i) => i + 1); // [1, 2, 3, ..., 30, 31]