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

//@version=5

// @description TODO: add library description here
library("bytime", overlay=true)

// @function TODO: to do something at the specified time.
// @returns TODO: ////Return =>>  ht = hour , mt = minute , st = second ,Dt = Day, Mt = month, Yt = year , dateTime = full time format./////////////

whatIsTheTime(_dst,T) =>
    TZ = T
    DST = _dst ? 1 : 0

    utcTime = 7 * 3600000 + timenow

    [math.floor(utcTime / 3600000) % 24, math.floor(utcTime / 60000) % 60, math.floor(utcTime / 1000) % 60, dayofmonth(int(utcTime), TZ), month(int(utcTime), TZ), year(int(utcTime), TZ), dayofweek(int(utcTime), TZ)]


export Gtime(string gmtSelect) =>
    [h, m, s, D, M, Y, A] = whatIsTheTime(false,gmtSelect)
    
    ht = h < 10 ? '0' + str.tostring(h) : str.tostring(h)
    mt = m < 10 ? '0' + str.tostring(m) : str.tostring(m)
    st = s < 10 ? '0' + str.tostring(s) : str.tostring(s)
    Dt = D < 10 ? '0' + str.tostring(D) : str.tostring(D)
    Mt = M < 10 ? '0' + str.tostring(M) : str.tostring(M)
    Yt = str.tostring(Y)
    dateTime = Dt + '/' + Mt + '/' + Yt + '-' + ht + ':' + mt + ':' + st
    
    [ht,mt,st,Dt,Mt,Yt,dateTime]


///////////////////////////////////////////////////////////////////
/////////////////////////////example///////////////////////////////
//Note : Remember to always add import when you call our library and change Gtime() to Timeset.Gtime() is used to access internal data.
// import hapharmonic/bytime/1 as Timeset
// [ht,mt,st,Dt,Mt,Yt,dateTime]=Timeset.Gtime()

///////////////////////////////////////////////////////////////////

gmtSelect       = input.string(title="Select Local Time Zone", defval="GMT+7", options=["GMT-7", "GMT-6", "GMT-5", "GMT-4", "GMT-3", "GMT-2", "GMT-1", "GMT", "GMT+1", "GMT+2",	"GMT+3","GMT+4","GMT+5","GMT+6","GMT+7","GMT+8","GMT+9","GMT+10","GMT+11","GMT+12","GMT+13"])

TH  = input.string('07','Hr:',inline='T',group='timefilter')
TM  = input.string('00','Min:',inline='T',group='timefilter')
TS  = input.string('00','Sec:',inline='T',group='timefilter')
////Return =>>  ht = hour , mt = minute , st = second ,Dt = Day, Mt = month, Yt = year , dateTime = full time format./////////////
[ht,mt,st,Dt,Mt,Yt,dateTime]=Gtime(gmtSelect)

/////////////Set a time to trigger an alert./////////////
ck = false
///hour    :     minute   :    second
if ht == TH and mt == TM and st == TS
    //some action
    //...
    //.
    ck := true
    
alertcondition(ck, title="Alert Test...",message= "Time =  {{timenow}}\n{{exchange}}:{{ticker}}\nprice = {{close}}\nvolume = {{volume}}")


label l = label.new(bar_index+5,close,text=dateTime,color=color.black,
  style=label.style_label_left,textcolor=color.white,
  textalign=text.align_left,size=size.huge)
label.delete(l[1])
///////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////
