Go Back   Dynamic Drive Forums > DD Scripts > Dynamic Drive scripts help
Search Dynamic Drive Forums:

Reply
 
Thread Tools Search this Thread
  #1  
Old 03-18-2005, 06:17 PM
thomas thomas is offline
New Comer (less than 5 posts)
 
Join Date: Mar 2005
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Angry DD Countdown Script II - Eastern Time Zone?

Script: DD Countdown Script II
http://www.dynamicdrive.com/dynamic...dhtmlcount2.htm

I have the script working but wanted to implement a certain Time Zone to the countdown.

I have something that is going to end on June 6, 2005 23:59:59 EST and did not know how to make the countdown end at the Eastern Standard Time Zone?

Thanks in advance.

Thomas
Reply With Quote
  #2  
Old 03-20-2005, 11:07 PM
jscheuer1's Avatar
jscheuer1 jscheuer1 is offline
No Kidding?
 
Join Date: Mar 2005
Location: SE PA USA
Posts: 18,996
Thanks: 19
Thanked 1,132 Times in 1,118 Posts
Blog Entries: 3
Default

Hope you haven't given up yet or your event has passed by the time you see this. Anyways, the script you are using uses the time as set on the user's computer. As is, that will return the time left until the time of your event as if it were occurring locally for the user. For many televised events, this is better than EST, also, by June 6th we may have daylight time to worry about as well. Local time of the user may be daylight or not depending upon convention in his/her zone. If you still want to go for EST, even though it will be EDT by then, I think. You can follow this line in the code:
Code:
var todayh=today.getHours()
with:
Code:
if ('number'==typeof today.getUTCHours()){ todayh=today.getUTCHours()-5;todayd=today.getUTCDate();
if (todayh<0) {todayh=todayh+24; todayd=todayd-1;}}
This will give us the hour in Universal Time (if available) -5 (EST), use -4 for an event in daylight time, but since it may now be the previous day, a little more work is needed. That explains the second added line. If UTC time is not available, the user will get the calculation based upon his/her local time.

Last edited by jscheuer1; 03-21-2005 at 06:25 AM. Reason: add error checking
Reply With Quote
  #3  
Old 04-01-2005, 03:59 PM
thomas thomas is offline
New Comer (less than 5 posts)
 
Join Date: Mar 2005
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Talking

Thank You for your help! I will add the new code and see what happens! Thanks again.

PS - I used a -4 since Daylight Savings time is tomorrow night and my event will be in June. Sound ok?
Reply With Quote
  #4  
Old 04-01-2005, 05:29 PM
jscheuer1's Avatar
jscheuer1 jscheuer1 is offline
No Kidding?
 
Join Date: Mar 2005
Location: SE PA USA
Posts: 18,996
Thanks: 19
Thanked 1,132 Times in 1,118 Posts
Blog Entries: 3
Default

Quote:
Originally Posted by thomas
I used a -4 since Daylight Savings time is tomorrow night and my event will be in June. Sound ok?
Yes sir! That's why I put that in. UTC time never varies for Daylight time. When I originally wrote on this, the time change was so far in the future I wasn't clear on when it would be. June 6th definitely is Daylight time. And since, as I said, UTC time never varies, it makes no difference what the current Eastern time is, only what it will be when the event occurs.
Reply With Quote
  #5  
Old 04-02-2005, 01:16 AM
mwinter mwinter is offline
Elite Coders
 
Join Date: Dec 2004
Location: UK
Posts: 2,361
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
Originally Posted by jscheuer1
if ('number'==typeof today.getUTCHours()){
If you're attempting to check that the getUTCHours method is supported, that isn't the way to go about it. You need to check that the method itself is available, not that it's return value is correct. If a host doesn't support a function, the script will error out - precisely what you should be trying to avoid.

In this instance,

Code:
if(today.getUTCHours) {
would be sufficient. However, I really don't believe it's necessary. The UTC methods have been supported since fourth generation browsers, and they're obsolete as it is.

By the way, constructing strings and using the parse method is a really obtuse way of doing this. Subtracting Date objects directly will result in the same millisecond value and is far more efficient.

Code:
function countdown() {
  var est    = new Date(),
      target = new Date(yr, mo, da, hr, min, sec);

  est.setUTCHours(est.getUTCHours - 5);
  dd = target - est;
  /* ... */
}
Untested, but I don't see how it would behave any differently.

Mike
Reply With Quote
  #6  
Old 04-02-2005, 05:09 AM
jscheuer1's Avatar
jscheuer1 jscheuer1 is offline
No Kidding?
 
Join Date: Mar 2005
Location: SE PA USA
Posts: 18,996
Thanks: 19
Thanked 1,132 Times in 1,118 Posts
Blog Entries: 3
Default

Quote:
Originally Posted by mwinter
if(today.getUTCHours) {
Cool! I really don't understand your use of set in the altered countdown function, must look it up when I get a chance. One thing, I noticed you created est=new Date(), not sure if it matters but, we don't know what time zone the user is in.

Added Later, I put your code in where it looked like it went and got:

Quote:
NaN days, NaN hours, NaN minutes, and NaN seconds left until Bulls vs Lakers game

Last edited by jscheuer1; 04-02-2005 at 05:17 AM.
Reply With Quote
  #7  
Old 04-02-2005, 10:25 AM
mwinter mwinter is offline
Elite Coders
 
Join Date: Dec 2004
Location: UK
Posts: 2,361
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
Originally Posted by jscheuer1
Cool! I really don't understand your use of set in the altered countdown function [...]
It depends why you're confused. The statement should actually read:

Code:
est.setUTCHours(est.getUTCHours() - 5);
Notice the function call now. This corrects the NaN problem.

With any of the Date manipulation methods, including the constructor itself, you can supply out-of-range values. When you do, the object will automatically cap the value, but adjust other fields too. For example, setting the 31st of November will result in a date of the 1st of December.

Quote:
One thing, I noticed you created est=new Date(), not sure if it matters but, we don't know what time zone the user is in.
Well, it will start off at local time, but it will be set to -0500 (EST) by the setUTCHours call later.

Quote:
I put your code in where it looked like it went and got [rubbish]
As I said above: correct the missing call and you should have no problems.

Mike
Reply With Quote
  #8  
Old 04-02-2005, 05:42 PM
jscheuer1's Avatar
jscheuer1 jscheuer1 is offline
No Kidding?
 
Join Date: Mar 2005
Location: SE PA USA
Posts: 18,996
Thanks: 19
Thanked 1,132 Times in 1,118 Posts
Blog Entries: 3
Default

Nice to know you sometimes mess up, like the rest of us, I was starting to get a complex. Anyways, your new modification makes it better, no NAN's. However, my version and the original version give 71 days to June 12th 2005, your code makes it 101 days. 71 is the correct amount as I type, according to a calendar. Off by a month, probably a simple fix for that.

Last edited by jscheuer1; 04-02-2005 at 05:44 PM.
Reply With Quote
  #9  
Old 04-02-2005, 06:01 PM
mwinter mwinter is offline
Elite Coders
 
Join Date: Dec 2004
Location: UK
Posts: 2,361
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
Originally Posted by jscheuer1
Nice to know you sometimes mess up, like the rest of us [...]
We're all human. I've made plenty of monumental cock-ups in the past, I can assure you. Hopefully, they'll stay in the past.

Quote:
Off by a month, probably a simple fix for that.
The month ordinal scheme for ECMAScript dates is zero-based (0 => January, 1 => February, etc.) Clearly, the script is one-based (it would be nice if that was mentioned in the script description, though I should have looked at the code more closely). Subtract one in the constructor call:

Code:
var est    = new Date(),
    target = new Date(yr, mo - 1, da, hr, min, sec);
Mike
Reply With Quote
  #10  
Old 04-02-2005, 06:28 PM
jscheuer1's Avatar
jscheuer1 jscheuer1 is offline
No Kidding?
 
Join Date: Mar 2005
Location: SE PA USA
Posts: 18,996
Thanks: 19
Thanked 1,132 Times in 1,118 Posts
Blog Entries: 3
Default

Quote:
Originally Posted by mwinter
Subtract one in the constructor call
Yeah, I just figured that out. One other problem is that in order to get the hours correct it needs to be:
Code:
function countdown() {
  var est    = new Date(),
      target = new Date(yr, mo-1, da, hr, min, sec);

  est.setUTCHours(est.getUTCHours()+1);
  dd = target - est;
for an event in daylight time (no adjustment for standard time), since I am in the EST zone, that leads me to believe you either have not broken out of the user's local time zone, or have done so redundantly with your original code.

Last edited by jscheuer1; 04-02-2005 at 06:31 PM.
Reply With Quote
Reply

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 08:17 AM.

Home - Contact Us - Archives - Link to DD - Top 

Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.