[SalesForce] Is DateWithin30Days(Date 1, Date 2) an Apex Method

I'm working on the #APEX Unit Testing unit on #TrailHead, and I saw what appears to be a very useful Date method, DateWithin30Days(date1, date2) This would be very useful for some of my projects, but I can't find it any where in the APEX documentation.

Here is the code sample:

public static Date CheckDates(Date date1, Date date2) {
    //if date2 is within the next 30 days of date1, use date2.  Otherwise use the end of the month
    if(DateWithin30Days(date1,date2)) {
        return date2;
    } else {
        return SetEndOfMonthDate(date1);
    }
}

Best Answer

The method DateWithin30Days(Date 1, Date 2) that you have referred here is not a standard Date method.

It is though still an Apex method but declared right within the class where you see this code. You are most likely looking at this code from trailhead, which you can always utilize for your purpose.

//method to check if date2 is within the next 30 days of date1
private static Boolean DateWithin30Days(Date date1, Date date2) {
    //check for date2 being in the past
        if( date2 < date1) { return false; }

        //check that date2 is within (>=) 30 days of date1
        Date date30Days = date1.addDays(30); //create a date 30 days away from date1
    if( date2 >= date30Days ) { return false; }
    else { return true; }
}