/** * This function returns the number of days in the month. * * @param $month (Optional) If empty, object's month. Default: empty. * @param $year (Optional) If empty, object's year. Default: empty. * * @returns The number of days in the month. * * @static If $month and $year are passed. */ function getDaysInMonth($month = '', $year = '') { if (!$month) { $month = $this->month; } if (!$year) { $year = $this->year; } switch ((int) $month) { case 1: return 31; case 2: return YDDate::isLeapYear($year) ? 29 : 28; case 3: return 31; case 4: return 30; case 5: return 31; case 6: return 30; case 7: return 31; case 8: return 31; case 9: return 30; case 10: return 31; case 11: return 30; case 12: return 31; } return 0; }
/** * This function returns the weekday as an integer. * 0 = Sunday - 6 = Saturday * * @param $date (Optional) A YDDate object, timestamp, array or string. * If null, the date of the object. Default: null. * @param $format (Optional) The format. Default: 'ISO'. * * @returns The weeday number. * * @static If $date is passed. */ function getWeekDay($date = null, $format = 'ISO') { if ($date === null) { $date = $this->parse($date, $format); } else { $date = YDDate::parse($date, $format); } if (!$date['day'] && !$date['month'] && !$date['year']) { return null; } $arr = array(0, 6, 2, 2, 5, 0, 3, 5, 1, 4, 6, 2, 4); $y = substr($date['year'], -2); $a = $date['day'] + $y + floor($y / 4) + $arr[$date['month']]; if (YDDate::isLeapYear($date['year']) && $date['month'] <= 2 && $date['day'] < 29) { $a--; } while ($a > 7) { $a -= 7; } if ($date['year'] != 2000 && $date['year'] % 100 == 0) { if ($date['year'] < 2000) { $a += (2000 - $date['year']) / 100; } else { $a -= 2 * (($date['year'] - 2000) / 100); } } return $a == 7 ? 0 : $a; }