TP-Docs
HTML5 Icon HTML5 Icon HTML5 Icon
TP on Social Media

Recent

Welcome to TinyPortal. Please login or sign up.

Members
  • Total Members: 3,963
  • Latest: BiZaJe
Stats
  • Total Posts: 195,917
  • Total Topics: 21,308
  • Online today: 728
  • Online ever: 8,223 (February 19, 2025, 04:35:35 AM)
Users Online
  • Users: 1
  • Guests: 461
  • Total: 462
  • @rjen

[Block] Recurring count down timer UTC

Started by Final60, February 14, 2009, 03:23:38 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Xarcell


Final60

QuoteIt seems there is some sort of quirk in the weekly code.  When it ticks a day off, it seems to be adding another day or something.  I am going to watch this thing for a whole week and see what it is doing.

Strange. As far as I am aware the script should work fine. Make sure your script isn't conflicting against another. like somwhere else there is "counter3" also.

QuoteIs it possible to have the countdown show weeks to an event?
I'll work on this soon for you :)

ZarPrime

Final60,

Saw you on. 

Last night, at midnight, when it was supposed to countdown to zero it added 2 days (weird).  Sometime during the day today it took off a day, and right now, it says 4 hours and 15 minutes are left.  It was set to go to zero at Midnight last night (Friday Morning), so right now it should say 6 days, 4 hours and 15 minutes but it doesn't.

I don't think I have anything else that should be interfering with this, but I'm going to look over the weekend.

ZarPrime

Dianna

#13
Quote from: Final60 on February 15, 2009, 04:52:36 PM
Quote from: Dianna on February 14, 2009, 05:04:29 AM
Hey, this is really cool!  Where do I put in the time that I want it to countdown too?  I want it to countdown to 10:00pm Pacific Standard Time.

ETA:  Oh duh, on the 16,0,0. Is that right? 

So mine would be 10,0,0? 

I'm thinking out loud that I would have to use the 2nd and 3rd counters for other time zones.

Very cool!  Thanks!

This script is set for UTC which is GMT+0 so for yor example you would use the following;

myCounter('counter', [
  [06,0,0, 'event starts in '],
]);


If I've worked it out right PST is GMT-8.
So for you to get the counter to count down to 10pm (PST) daily you have it set to 06(am gmt+0),0(mins),0(secs). Its possible to use timeoffset, but in both cases you need to know how many hours to offset and change the code accordingly, so this may be the simpler option.


Hi Final60, thank you so much! I love the counter!!!!  For my clients this is an awesome feature for their site!  I just discovered one thing for my client that is a snag in me being able to use it. My client has a weekly talk radio show every night 6 nights a week. The countdown ROCKS on the site to show the countdown to the next show. I just realize how they do not do a show on Sunday. So is there a way to tweak the coding to count down 48 hours on the 7th day so it would skip the Sunday night? 

here's my site page just in case www.schreeandbaby.com/index.php and it's on the right hand block.

ZarPrime

Final60,

I have been trying to sort out the weekly counter errors I've been having again.  I've been watching this thing for the past couple of weeks and it's still just not working right.  I know the weekly counter was not the original purpose of this snippet, but I would like to figure out why these quirks are happening.  I have it set to tick down to zero on day 5, and 5AM UTC (Friday Morning at 5AM).  That means that in my time zone, it should count down to zero at Midnight Thursday night (US Eastern time zone).

Every once in a while, a day will be added, and then taken back off later in the day.  Right now, it's Saturday morning at 7 AM Eastern time here.  The timer should say "5 days 17 hrs 0 min 0 sec" but it says "17 hrs 0 min 0 sec" instead.

I used to be pretty good at spotting errors in script and have looked at the code inside and out, and I also had another coder take a look at it, and he thinks it looks OK as well, but I can't not figure out what is wrong with it.  At your suggestion, I changed all instances of "counter" in my code to "countre" just to make sure that nothing else was interfering with it.  I've also set this code up to run a regular html page that I have running in another tab in my browser, and it is doing the exact same thing as it's doing in my Forum, so it's not anything to do with my Forum setup.

I am going to ask you to take a second look at this code one more time, and if we can't figure out what is causing the problems, I am just not going to be able to use it, as much as I would like to.  The current code I'm using is shown below.

Thanks,
ZarPrime

<div id="countre3">Loading...</div>
<script type="text/javascript">
     function mycountre(o, timeArray){
         var countre = document.getElementById(o);
         if(!countre) {
             return;
         }

         // helper functions
         function mksec(day, h, m, s){ return day*24*60*60+h*60*60+m*60+s; }
         function toTimeString(sec, showZero){
             var d=Math.floor(sec/(60*60*24))
             var h=Math.floor(sec/(60*60)%24);
             var m=Math.floor((sec/60) % 60);
             var s=sec % 60;
             var ret=d+'days '+h+'hrs '+m+'min '+s+'sec';
             if(showZero){
                return ret;
             }else if(d==0 && h==0 && m==0){
                return s+'sec';
             }else if(d==0){
                return h+'hrs '+m+'min '+s+'sec';
             }else if(d==0 && h==0){
                return m+'min '+s+'sec';
             }else {
                return ret;
             }
         }
         //
         var secArray = [];
         var dayNow = new Date().getDay();
         for(var i=0;i<timeArray.length;i++){
            var day=timeArray[i][0];
            if(day==-1){
                day=dayNow;
            }
             secArray.push({
                day: timeArray[i][0],
                sec: mksec(day, timeArray[i][1], timeArray[i][2], timeArray[i][3]),
                msg: timeArray[i][4] || false,
                showZero: timeArray[i][5] || false
             });
         }
         secArray.sort(function(a,b){ return a.sec-b.sec;});

         // timer code - will be called around each second (~1000 ms)
         function updatecountre(){
             // get current UTC time in seconds
             var d=new Date();
             var secNow = mksec(d.getDay(), d.getUTCHours(), d.getUTCMinutes(), d.getUTCSeconds());
             // find next event
             var nextIndex=0;
             for(var i=0;i<secArray.length; i++){
                 var diff = secArray[i].sec-secNow;
                 if(diff>0){
                     nextIndex=i;
                     break;
                 }
             }
             //
             var diff=secArray[nextIndex].sec-secNow;
             var prevDiff=diff;
             if(diff<0){
                var dayDiff = 6-secArray[nextIndex].day;
                if(secArray[nextIndex].day == -1){
                    dayDiff=0;
                }
                diff=(dayDiff+1)*24*60*60-Math.abs(diff);
             }
             var str='';
             // get message if there is any set
             if(secArray[nextIndex].msg){
                 str=secArray[nextIndex].msg;
             }
             var timeString = toTimeString(diff, secArray[nextIndex].showZero);
             if(str.match('@{countre}')!=null){
                 str=str.replace(/@{countre}/, timeString);
             }else if(str.indexOf(' ')==0){ // message starts with space
                 str=timeString+str;
             }else{ // no specific hint where to put countre, so display it after message
                 str+=timeString;
             }
             countre.innerHTML=str;
        }
     
         setInterval(updatecountre, 1000);
         
     };
mycountre('countre3', [ [5, 5, 0, 0, '<center><b>Next Turns are Due in </b><p class="smalltext"> @{countre}</center>', false] ]);
</script>

chesterfield

Just noticed as the clocks have changed the timer is now an hour in front? is there a way to detect this seasonal change so that the timer works all year round?

thanks
mark

Min2001

There is nothing wrong with the script you'r using but you are overlooking something very important if you wanted to set the time to be 5PM it needs to be inputted as 17 as it is a 24 hour clock. also take into account when adding the times you dont forget to put the clocks back or forward 1 hour according to daylight saving time....great script by the way :)

sandmannd

Not quite sure what I'm doing wrong with this. I can choose "html/javascript" I assume that's what I choose. I put the code in and go to save it and it just spins saying "loading". If I go to my home page to see it, it does the same thing. Any advice on it?

sandmannd

I got it fixed, put it in as PHP code and then saved it as Javascript and it works. Very nice mod.  :up:

solio

#19
 ;D

Hey nice script, thank u .... however, I have 1 problem....

I'm using it to repeat each day, and it works very nicely....

4 hrs 23mins 14secs

(the day does not display which is correct of course, since it is only being used for 24hrs).

HOWEVER I notice when it gets down to the last 10 seconds, it then displays:

1 day 0 hrs 0 mins 10sec

the "1 day" part comes from ???  How can I remove that?

Also, it seems that at the very same time (10 second mark), IE crashes - it must be a bug in the script at that moment methinks!

Any help appreciated - otherwise great script!

(here's my code)



<div id="counter">
  <div align="left">Loading...</div>
</div>
<div align="left">
  <script type="text/javascript">
     function myCounter(o, timeArray){
         var counter = document.getElementById(o);
         if(!counter) {
             return;
         }

         // helper functions
         function mksec(day, h, m, s){ return day*24*60*60+h*60*60+m*60+s; }
         function toTimeString(sec, showZero){
             var d=Math.floor(sec/(60*60*24))
             var h=Math.floor(sec/(60*60)%24);
             var m=Math.floor((sec/60) % 60);
             var s=sec % 60;
             var ret=d+'days '+h+'hrs '+m+'min '+s+'sec';
             if(showZero){
                return ret;
             }else if(d==0 && h==0 && m==0){
                return s+'sec';
             }else if(d==0){
                return h+'hrs '+m+'min '+s+'sec';
             }else if(d==0 && h==0){
                return m+'min '+s+'sec';
             }else {
                return ret;
             }
         }
         //
         var secArray = [];
         var dayNow = new Date().getDay();
         for(var i=0;i<timeArray.length;i++){
            var day=timeArray[i][0];
            if(day==-1){
                day=dayNow;
            }
             secArray.push({
                day: timeArray[i][0],
                sec: mksec(day, timeArray[i][1], timeArray[i][2], timeArray[i][3]),
                msg: timeArray[i][4] || false,
                showZero: timeArray[i][5] || false
             });
         }
         secArray.sort(function(a,b){ return a.sec-b.sec;});

         // timer code - will be called around each second (~1000 ms)
         function updateCounter(){
             // get current UTC time in seconds
             var d=new Date();
             var secNow = mksec(d.getDay(), d.getUTCHours(), d.getUTCMinutes(), d.getUTCSeconds());
             // find next event
             var nextIndex=0;
             for(var i=0;i<secArray.length; i++){
                 var diff = secArray[i].sec-secNow;
                 if(diff>0){
                     nextIndex=i;
                     break;
                 }
             }
             //
             var diff=secArray[nextIndex].sec-secNow;
             var prevDiff=diff;
             if(diff<0){
                var dayDiff = 6-secArray[nextIndex].day;
                if(secArray[nextIndex].day == -1){
                    dayDiff=0;
                }
                diff=(dayDiff+1)*24*60*60-Math.abs(diff);
             }
             var str='';
             // get message if there is any set
             if(secArray[nextIndex].msg){
                 str=secArray[nextIndex].msg;
             }
             var timeString = toTimeString(diff, secArray[nextIndex].showZero);
             if(str.match('@{counter}')!=null){
                 str=str.replace(/@{counter}/, timeString);
             }else if(str.indexOf(' ')==0){ // message starts with space
                 str=timeString+str;
             }else{ // no specific hint where to put counter, so display it after message
                 str+=timeString;
             }
             counter.innerHTML=str;
        }
     
         setInterval(updateCounter, 1000);
         
     };
myCounter('counter', [ [-1, 24, 00, 10, '<span class="lcdtext">Today\'s deadline </span><span class="lcdstyle">@{counter} </span>', false] ]);
</script>
 


This website is proudly hosted on Crocweb Cloud Website Hosting.