paolo@bimodesign.com | +34 608 61 64 10

Framework

        

Check mm/dd format date

This function checks if the input date with this format (MM/DD) - without year - is valid. Also calculates the last day of Febraury of current year.

The comments into the code explains this funcion

    /**
     * Check if the day of month (start and end) are valid.
     *
     * @param integer $start The value of the day
     * @param integer $start The value of the month
     * 
     * @return exception
     */

    protected function checkDayAndMonth($day, $month)
    {
        /*
         *  Calculate the last day of Febraury of current year
         */
        $lastDayFebraury=date('t', mktime(0, 0, 0, 2, 1, date("Y")))."-02-".date("Y");

        /*
         *  Check if today is before or after the last day of Febraury of current year
         */
        $current          = time();
        $lastDayFebraury = strtotime($lastDayFebraury);

        /*
         *  Calculate the last day from the input data
         */
        if ($current <= $lastDayFebraury) {
            $numDayofMonth = cal_days_in_month(CAL_GREGORIAN, $month, date("Y"));
        } else {
            if ($month == 2) {
                $numDayofMonth = cal_days_in_month(CAL_GREGORIAN, $month, date('Y', strtotime('+1 year')));
            } else {
                $numDayofMonth = cal_days_in_month(CAL_GREGORIAN, $month, date("Y"));
            }
        }

        /*
         *  Check if the input day value is correct with the input month day
         */
        if ($day > $numDayofMonth) {
            throw ....
        }
    }