Community discussions

MikroTik App
 
SubZero
just joined
Topic Author
Posts: 7
Joined: Wed Aug 15, 2012 1:44 am

about showing the remaining time in the status page

Wed Aug 15, 2012 2:54 am

Hello everyone

in sum .. :D

I want to show the time remaining in the status page

So i add the code: $(session-time-left) on it

Everything is fine

the time remaining shows like this: 5w3d9h4m

So in fact this means that remaining 5 weeks and 3 days, 9 hours and 4 minutes

All I want is to replace this: 5w3d9h4m
to this: 5 weeks and 3 days, 9 hours and 4 minutes

I think that it is very easy

Sorry I'm Newbie, And Sorry for my bad English :)
 
SubZero
just joined
Topic Author
Posts: 7
Joined: Wed Aug 15, 2012 1:44 am

Re: about showing the remaining time in the status page

Tue Aug 21, 2012 5:58 pm

where are you people!!!???
 
User avatar
boen_robot
Forum Guru
Forum Guru
Posts: 2400
Joined: Thu Aug 31, 2006 4:43 pm
Location: europe://Bulgaria/Plovdiv

Re: about showing the remaining time in the status page

Tue Aug 21, 2012 6:54 pm

You'd need to parse this with JavaScript.

I think it will be easiest with string.split, like:
<div id="timeLeft">$(session-time-left)</div>
<script type="text/javascript">
var timeLeft = "$(session-time-left)".split(/\d+/);
for (var i =0, l = timeLeft.length; i<l; ++i) {
    switch(timeLeft[i]) {
    case "w":
        timeLeft[i] = " weeks, ";
        break;
    case "d":
        timeLeft[i] = " days, ";
        break;
    case "h":
        timeLeft[i] = " hours, ";
        break;
    case "m":
        timeLeft[i] = " minutes";
        break;
    }
}
document.getElementById("timeLeft").innerHTML = timeLeft.join();
</script>
 
SubZero
just joined
Topic Author
Posts: 7
Joined: Wed Aug 15, 2012 1:44 am

Re: about showing the remaining time in the status page

Wed Aug 22, 2012 2:46 am

You'd need to parse this with JavaScript.

I think it will be easiest with string.split, like:
<div id="timeLeft">$(session-time-left)</div>
<script type="text/javascript">
var timeLeft = "$(session-time-left)".split(/\d+/);
for (var i =0, l = timeLeft.length; i<l; ++i) {
    switch(timeLeft[i]) {
    case "w":
        timeLeft[i] = " weeks, ";
        break;
    case "d":
        timeLeft[i] = " days, ";
        break;
    case "h":
        timeLeft[i] = " hours, ";
        break;
    case "m":
        timeLeft[i] = " minutes";
        break;
    }
}
document.getElementById("timeLeft").innerHTML = timeLeft.join();
</script>
thank u 4 reply
but nothing changed after i add the script :(
 
User avatar
boen_robot
Forum Guru
Forum Guru
Posts: 2400
Joined: Thu Aug 31, 2006 4:43 pm
Location: europe://Bulgaria/Plovdiv

Re: about showing the remaining time in the status page

Wed Aug 22, 2012 1:18 pm

I tested the script, and although it didn't produced the expected results, it did make a difference... maybe JavaScript wasn't enabled in your browser when you tested?

Anyway, here's a simpler script that produces the correct results:
<div id="timeLeft">$(session-time-left)</div>
<script type="text/javascript">
document.getElementById("timeLeft").innerHTML = "$(session-time-left)".replace("w", " weeks, ").replace("d", " days, ").replace("h", " hours and ").replace("m", " minutes.");
</script>
 
SubZero
just joined
Topic Author
Posts: 7
Joined: Wed Aug 15, 2012 1:44 am

Re: about showing the remaining time in the status page

Wed Aug 22, 2012 3:44 pm

I tested the script, and although it didn't produced the expected results, it did make a difference... maybe JavaScript wasn't enabled in your browser when you tested?

Anyway, here's a simpler script that produces the correct results:
<div id="timeLeft">$(session-time-left)</div>
<script type="text/javascript">
document.getElementById("timeLeft").innerHTML = "$(session-time-left)".replace("w", " weeks, ").replace("d", " days, ").replace("h", " hours and ").replace("m", " minutes.");
</script>
now it works

thank u very much bro :)
 
navyday
just joined
Posts: 3
Joined: Thu Nov 13, 2014 1:17 pm
Location: Greece

Re: about showing the remaining time in the status page

Sat Sep 05, 2015 1:33 pm

I tested the script, and although it didn't produced the expected results, it did make a difference... maybe JavaScript wasn't enabled in your browser when you tested?

Anyway, here's a simpler script that produces the correct results:
<div id="timeLeft">$(session-time-left)</div>
<script type="text/javascript">
document.getElementById("timeLeft").innerHTML = "$(session-time-left)".replace("w", " weeks, ").replace("d", " days, ").replace("h", " hours and ").replace("m", " minutes.");
</script>
now it works

thank u very much bro :)


how to replace this code and that would put

Sorry I'm Newbie, And Sorry for my bad English :?