"use strict" ;

const monthDays = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31] ;

/**
 * Returns the numbers of days in a specified month.
 * @return The numbers of days in a specified month.
 * @name daysInMonth
 * @memberof core.date
 * @function
 * @instance
 * @param {Date} [date] - The date (or now) to search the number of days in a month.
 * @example
 * trace( daysInMonth(new Date(2016,0,1)) ) ; // 31
 * trace( daysInMonth(new Date(2016,1,1)) ) ; // 29
 * trace( daysInMonth(new Date(2017,0,1)) ) ; // 31
 */
const daysInMonth = ( date = null ) =>
{
    if( !(date instanceof Date) )
    {
        date = new Date() ;
    }

    let y = date.getFullYear() ;
    let m = date.getMonth() ;

    if ( ( ( y%4 === 0 && y%100 !== 0 ) || y%400 === 0 ) && m === 1 )
    {
    	return 29 ;
    }

    return monthDays[m] ;
};

export default daysInMonth ;
