FunctionDaysInMonth
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © RicardoSantos

//@version=5

// @description Method to find the number of days in a given month of year.
library(title='FunctionDaysInMonth')

// @function Method to find the number of days in a given month of year.
// @param year int, year of month, so we know if year is a leap year or not.
// @param month int, month number.
// @returns int
export days_in_month (int year_value, int month_value) => //{
    switch
        (month_value < 1) => runtime.error('FunctionDaysInMonth -> days_in_month(): "month" must be a integer over or equal to 1')
        (month_value > 12) => runtime.error('FunctionDaysInMonth -> days_in_month(): "month" must be a integer under or equal to 12')
    //
    int _is_leap_year_february = (year_value % 4 == 0) and (month_value == 2) ? 1 : 0
    28 + _is_leap_year_february + (month_value + math.floor(month_value / 8)) % 2 + 2 % month_value + 2 * math.floor(1 / month_value)
//{ usage:
var string[] months = array.from("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December")
int i_year = input.int(2019)
int i_month = input.int(1)
int days = days_in_month(i_year, i_month)
var label la = label.new(bar_index, 0.0, str.format('{0} in Year {1} has {2} days.', array.get(months, i_month-1), i_year, days))
//{ Remarks:
//      https://cmcenroe.me/2014/12/05/days-in-month-formula.html
//}}}
