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

//@version=5

// @description Utils for time series
library("timeUtils", overlay=false)


// @function Calculates how many full trading days left until the end of the current month. (It doesn't take into account market holidays)
// @returns int[] series of the remaining trading days until the end of the month. 
export tradingDaysTillEndOfMonth() =>
    int[] daysInMonth = array.from(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31)
    DaysOfCurrentMonth = array.get(daysInMonth, month(time)-1)
    if month(time) == 2 and year(time) % 4 == 0 // Compensate February with 29 days
        DaysOfCurrentMonth += 1
    weekendDaysTillEndofmonth = (math.floor((DaysOfCurrentMonth - dayofmonth(time) + dayofweek(time))/7)) + (math.floor((DaysOfCurrentMonth - dayofmonth(time) + dayofweek(time)-1)/7))
    tradingDaysTillEndofmonth = DaysOfCurrentMonth - dayofmonth(time) - weekendDaysTillEndofmonth[0]

// @function Check if the current bar is inside the time range
// @returns bool[] series contains true for the bars that are inside the time range, false otherwise
export insideDateRange(int fromYear, int fromMonth=1, int fromDay=1, int toYear, int toMonth=12, int toDay=31) =>
    start = timestamp(fromYear, fromMonth, fromDay)
    end = timestamp(toYear, toMonth, toDay, 23, 59)
    inRange = time > start and time < end
    
