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

//@version=5

// @description: All functions to be used for session or time processing
library("SessionAndTimeFct_public", true)

// @function: Check if actual bar is in specific session with specific time zone
// @param sessionTime: session time to check
// @param sessionTimeZone: time zone to use
export is_in_session(string sessionTime, string sessionTimeZone) =>
    not na(time(timeframe.period, sessionTime, sessionTimeZone))

// @function: Check if actual bar the first bar of a specific session
// @param sessionTime: session time to check
// @param sessionTimeZone: time zone to use
export is_session_start(string sessionTime, string sessionTimeZone=syminfo.timezone) =>
    inSess = not na(time(timeframe.period, sessionTime, sessionTimeZone))
    inSess and not inSess[1]

// @function: Check if a new day started
// @param sessionTime: time zone to use
export is_new_day(string timeZone) =>
	dayofmonth(time, timeZone) != dayofmonth(time, timeZone)[1]

// @function: Check if a new week started
// @param sessionTime: time zone to use
export is_new_week(string timeZone) =>
	weekofyear(time, timeZone) != weekofyear(time, timeZone)[1]

// @function: Check if a new month started
// @param sessionTime: time zone to use
export is_new_month(string timeZone) =>
	month(time, timeZone) != month(time, timeZone)[1]

// @function: Check if an element is to show compared to a specific timeframe >
// @param base: S for seconds, m for minutes, D for days, W for weeks and M for months
// @param value: value of base to compare
export is_element_to_show_with_tf_up(string base, int value) =>
    
    // value to return
    bool res = false

    // Seconds
    if(base == 'S')
        res := timeframe.multiplier >  value

    // Minutes
    if(base == 'm')
        res := (timeframe.isminutes and timeframe.multiplier > value) or timeframe.isdaily or timeframe.isweekly or timeframe.ismonthly

    // Days
    if(base == 'D')
        res := timeframe.isdaily and timeframe.multiplier > value or timeframe.isweekly or timeframe.ismonthly

    // Weeks
    if(base == 'W')
        res := timeframe.isweekly and timeframe.multiplier > value or timeframe.ismonthly  

    // Months
    if(base == 'M')
        res := timeframe.isminutes and timeframe.multiplier > value

    // Return boolean result
    res

// @function: Check if an element is to show compared to a specific timeframe <
// @param base: S for seconds, m for minutes, D for days, W for weeks and M for months
// @param value: value of base to compare
export is_element_to_show_with_tf_down(string base, int value) =>
    
    // value to return
    bool res = false

    // Seconds
    if(base == 'S')
        res := timeframe.multiplier <  value

    // Minutes
    if(base == 'm')
        res := timeframe.isminutes and timeframe.multiplier < value

    // Days
    if(base == 'D')
        res := (timeframe.isdaily and timeframe.multiplier < value) or timeframe.isminutes

    // Weeks
    if(base == 'W')
        res := timeframe.isweekly and timeframe.multiplier < value or timeframe.isminutes or timeframe.isdaily

    // Months
    if(base == 'M')
        res := timeframe.isminutes and timeframe.multiplier < value or timeframe.isminutes or timeframe.isdaily or timeframe.isweekly

    // Return boolean result
    res