Utilities

Along with exported components, there are utility date-based functions available for you to use. the first parameter of utils function, is the locale language of utils (default to en). Here are some examples:

Get Today

import { utils } from 'react-modern-calendar-datepicker';

const gregorianToday = utils().getToday(); // { year: 2020, month: 7, day: 3 }
const persianToday = utils('fa').getToday(); // { year: 1399, month: 4, day: 13 }

Days Precedence

import { utils } from 'react-modern-calendar-datepicker';
const day1 = { year: 2019, month: 10, day: 1 };
const day2 = { year: 2019, month: 10, day: 2 };

const { isBeforeDate } = utils();
const isDay1BeforeDay2 = isBeforeDate(day1, day2); // ✅ true
const isDay2BeforeDay1 = isBeforeDate(day2, day1); // ❌ false