Jump to content
UBot Underground

Recommended Posts

I just wanted to share function that I wrote for adding time interval to specific date. It seems that UBOT missing basic date manipulation functions, so I decided to write my own. I hope it will be useful to someone

 

define $date_add(#d, #interval, #ivalue) {
    if($comparison(#interval,"=","SECONDS")) {
        then {
            set(#st,$eval("var d=new Date('{#d}');d.setSeconds(d.getSeconds()+{#ivalue});d;"),"Local")
        }
    }
    if($comparison(#interval,"=","MINUTES")) {
        then {
            set(#st,$eval("var d=new Date('{#d}');d.setMinutes(d.getMinutes()+{#ivalue});d;"),"Local")
        }
    }
    if($comparison(#interval,"=","HOURS")) {
        then {
            set(#st,$eval("var d=new Date('{#d}');d.setHours(d.getHours()+{#ivalue});d;"),"Local")
        }
    }
    if($comparison(#interval,"=","DAYS")) {
        then {
            set(#st,$eval("var d=new Date('{#d}');d.setDate(d.getDate()+{#ivalue});d;"),"Local")
        }
    }
    if($comparison(#interval,"=","MONTHS")) {
        then {
            set(#st,$eval("var d=new Date('{#d}');d.setMonth(d.getMonth()+{#ivalue});d;"),"Local")
        }
    }
    set(#MM,$eval("var d1=new Date('{#st}');('0'+(d1.getMonth()+1)).slice(-2);"),"Local")
    set(#DD,$eval("var d1=new Date('{#st}');('0'+d1.getDate()).slice(-2);"),"Local")
    set(#YYYY,$eval("var d1=new Date('{#st}');d1.getFullYear();"),"Local")
    set(#hh,$eval("var d1=new Date('{#st}');('0'+d1.getHours()).slice(-2);"),"Local")
    set(#mm,$eval("var d1=new Date('{#st}');('0'+d1.getMinutes()).slice(-2);"),"Local")
    set(#ss,$eval("var d1=new Date('{#st}');('0'+d1.getSeconds()).slice(-2);"),"Local")
    return("{#MM}/{#DD}/{#YYYY} {#hh}:{#mm}:{#ss}")
}

Here is how you can use it:
 

alert($date_add($date, "MONTHS", "-2"))
alert($date_add($date, "MONTHS", "1"))
alert($date_add($date, "SECONDS", "60"))
alert($date_add($date, "MINUTES", "5"))
alert($date_add($date, "HOURS", "4"))
alert($date_add($date, "DAYS", "10"))

For example, you can call some function as many times as possible for the next 5 minutes:
 

set(#tmpDate,$date_add($date, "MINUTES", "5"),"Global")
loop while($comparison($date,"<",#tmpDate)) {
    callMyFunction
}
  • Like 3
Link to post
Share on other sites

HelloInsomnia, maybe I miss something but the plugin you mentioned does only date formatting.

I didn't find any reference to adding time interval to the given date.

 

Please correct me if I'm wrong

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...