Comparison

Is valid 1.0.0+

Check the date and time.

                
let p = new PersianDate('1400/1/1 13:7','jalali');
p.isValid(); // true

PersianDate.isValid('jalali', 1400, 1, 1, 13, 7,0,0); // true
                
        

If you use Jalali calendar, validate is done for Jalali calendar and if you use the Gregorian calendar, validate is done for Gregorian calendar

                
p.calendar('jalali').isValid(1400,2,31);    // true

p.calendar('gregorian').isValid(2021,2,31); // false
                
        

Is valid date

                
let p = new PersianDate('1400/1/1 25:00','jalali');
p.isValidDate(); // true

PersianDate.isValidDate('jalali', 1400 , 13, 1); // false
                
        

Is valid time

                
let p = new PersianDate('1400/1/1 12:00','jalali');
p.isValidTime(); // true

PersianDate.isValidTime('jalali', 25, 10, 0, 0); // false
                
        

Is leap year 1.0.0+

Determines if the year is a leap year or not.

                
PersianDate.isLeapYear('jalali', 1399); // true
PersianDate.isLeapYear('gregorian', 2020); // true

let p = new PersianDate('1400/1/1','jalali');
p.isLeapYear(); // false
                
        

isLeapYear method has the different behavior in Jalali calendar and Gregorian calendar

                
p.calendar('jalali').isLeapYear(1399);    // true

p.calendar('gregorian').isLeapYear(2020); // true
                
        

Is same 1.1.0+

Check the date is the same as another date.

                
let p = new PersianDate('1399/6/1 12:20:30.235','j');

p.isSame(1399, 6, 1, 12, 20, 30, 235); // true

p.isSame([1399, 6]);   // true  --> this just compare the year and month

p.isSame('1399/13/1'); // false --> if date is not valid, returns false


p.calendar('g').parse('2020-6-1 12:20:30.235');

p.isSame(2020, 6, 1, 12, 20, 30, 235); // true

p.isSame([2020, 6]);   // true  --> this just compare the year and month

p.isSame('2020-13-1'); // false --> if date is not valid, returns false
                
        

1. You can pass the PersianDate instance, String, Array, Object, Numbers and Date instance to this method

2. If use this method without the parameter, this date compares with now

Is before 1.2.0+

Check the date is before another date.

                
let p = new PersianDate('1399/6/1 12:20:30.235','j');

p.isBefore(1399, 7, 1, 12, 20, 30, 235); // true

p.isBefore([1399, 6]);   // false

p.isBefore('1399/13/1'); // false --> if date is not valid, returns false


p.calendar('g').parse('2020-6-1 12:20:30.235');

p.isBefore(2020, 7, 1, 12, 20, 30, 235); // true

p.isBefore([2020, 6]);   // false

p.isBefore('2020-13-1'); // false --> if date is not valid, returns false
                
        

Like isSame method:

1. You can pass the PersianDate instance, String, Array, Object, Numbers and Date instance to this method

2. If use this method without the parameter, this date compares with now

Is after 1.2.0+

Check the date is after another date.

                
let p = new PersianDate('1399/6/1 12:20:30.235','j');

p.isAfter(1399, 5, 1, 12, 20, 30, 235); // true

p.isAfter([1399, 6]);   // true

p.isAfter('1399/13/1'); // false --> if date is not valid, returns false


p.calendar('g').parse('2020-6-1 12:20:30.235');

p.isAfter(2020, 5, 1, 12, 20, 30, 235); // true

p.isAfter([2020, 6]);   // true

p.isAfter('2020-13-1'); // false --> if date is not valid, returns false
                
        

Like isBefore method:

1. You can pass the PersianDate instance, String, Array, Object, Numbers and Date instance to this method

2. If use this method without the parameter, this date compares with now

Is same or before 1.3.0+

Check the date is before or the same as another date.

                
let p = new PersianDate('1399/6/1 12:20:30.235','j');

p.isSameOrBefore(1399, 6, 1, 12, 20, 30, 235); // true

p.isSameOrBefore([1399, 6]);   // false

p.isSameOrBefore('1399/13/1'); // false --> if date is not valid, returns false


p.calendar('g').parse('2020-6-1 12:20:30.235');

p.isSameOrBefore(2020, 6, 1, 12, 20, 30, 235); // true

p.isSameOrBefore([2020, 6]);   // false

p.isSameOrBefore('2020-13-1'); // false --> if date is not valid, returns false
                
        

Like isAfter method:

1. You can pass the PersianDate instance, String, Array, Object, Numbers and Date instance to this method

2. If use this method without the parameter, this date compares with now

Is same or after 1.3.0+

Check the date is after or the same as another date.

                
let p = new PersianDate('1399/6/1 12:20:30.235','j');

p.isSameOrAfter(1399, 6, 1, 12, 20, 30, 235); // true

p.isSameOrAfter([1399, 6]);   // true

p.isSameOrAfter('1399/13/1'); // false --> if date is not valid, returns false


p.calendar('g').parse('2020-6-1 12:20:30.235');

p.isSameOrAfter(2020, 6, 1, 12, 20, 30, 235); // true

p.isSameOrAfter([2020, 6]);   // true

p.isSameOrAfter('2020-13-1'); // false --> if date is not valid, returns false
                
        

Like isSameOrBefore method:

1. You can pass the PersianDate instance, String, Array, Object, Numbers and Date instance to this method

2. If use this method without the parameter, this date compares with now

Is between 1.3.0+

Check the date is between two other dates.

                
let p = new PersianDate("1399/6/1 12:20:30.235",'j');

p.isBetween([1399, 5, 1, 12, 20, 30, 235], "1399/7/1 12:20:30.235"); // true

p.isBetween('1399/1/1'); // true --> if you not pass the date, compare with now date

p.isBetween("1399/7/1", "1399/13/1"); // false --> if date given is not valid return false

p.isBetween("1399/7/1", "1399/5/1"); // false --> the smallest date should be a first parameter

p.isBetween("1399", "1400"); // false --> this just compare the year
                
        

You can pass the PersianDate instance, String, Array, Object and Date instance to this method

The three argument determines the method of compare. [ includes the date itself also and ( excludes the date itself for compare.

            
p.isBetween("1399", "1400", "[)");         // true

p.isBetween("1399/5", "1399/6", "[)");     // false

p.isBetween("1399/5", "1399/6", "(]");     // true

p.isBetween("1399/6/1", "1399/6/1", "[]"); // true
            
        

Is in array 2.6.0+

Check the date is in array of dates.

                
let p = new PersianDate("1399/6/1 12:20:30.235",'j');

p.isInArray([[1399, 6, 1, 12, 20, 30, 235], "1399/7/1 12:20:30.235"]); // true

p.isInArray(["1399/1/1", "1399/7/1"]); // false

p.isInArray("1399/7/1", "1399/6/1"); // true

p.isInArray("1399", "1400"); // true
                
        

You can pass the PersianDate instance, String, Array, Object and Date instance to this method

Is Date 1.3.0+

Check the input is instance of Date or not.

                
PersianDate.isDate(new Date()); // true

p.isDate(); // false

p.isDate(new PersianDate()); // false
                
        

Is PersianDate 1.3.0+

Check the input is instance of PersianDate or not.

                
PersianDate.isPersianDate(p); // true

p.isPersianDate(new Date()); // false

p.isPersianDate(new PersianDate()); // true
                
        

Min 1.4.0+

Returns the minimum of the given dates.

                
let p = new PersianDate()

let nowruz = p.clone().parse("1400/1/1");

let firstOfYear = p.clone().calendar('g').parse("2020-1-1");

p.min(nowruz, [1399, 7, 2], { y: 1399, M: 10, d: 1 }, "1399-7-1 12:30"); // "1399-7-1 12:30"

p.calendar('g').min(firstOfYear, [2020, 7, 2], { y: 2020, M: 10, d: 1 }, "2020-7-1 12:30"); // firstOfYear
                
        

1. You can pass the PersianDate instance, String, Array, Object and Date instance without limit to this method

2. if parameters not send or invalid parameters send, returns false

Max 1.4.0+

Returns the maximum of the given dates.

                
let p = new PersianDate()

let nowruz = p.clone().parse("1400/1/1");

let firstOfYear = p.clone().calendar('g').parse("2020-1-1");

p.max(nowruz, [1399, 7, 2], { y: 1399, M: 10, d: 1 }, "1399-7-1 12:30"); // nowruz

p.calendar('g').max(firstOfYear, [2020, 7, 2], { y: 2020, M: 10, d: 1 }, "2020-7-1 12:30"); // { y: 2020, M: 10, d:1 }
                
        

1. You can pass the PersianDate instance, String, Array, Object and Date instance without limit to this method

2. if parameters not send or invalid parameters send, returns false