473,487 Members | 2,483 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

countdown script problem (months remaining occasionally incorrect)

I am having problems with the following countdown script. For some reason,
the number of months is occasionally wrong. I can't quite put my finger on
the problem. Any assistance or recommendation from someone more knowlegable
than me would be appreciated. Thanks much.

<script>
ty=2005;to=08;td=31;th=24;tm=0;ts=0;
function e(){
ny=0;no=0;nd=0;nh=0;nm=0;ns=0;n=new Date();

if(n.getYear()>ty){t.s.value=0;t.m.value=0;t.h.val ue=0;t.d.value=0;t.o.value
=0;t.y.value=0;}
else{
ns=ns+ts-n.getSeconds();if(ns<0){ns=60+ns;nm=-1;}t.s.value=ns;
nm=nm+tm-n.getMinutes();if(nm<0){nm=60+nm;nh=-1;}t.m.value=nm;
nh=nh+th-n.getHours();if(nh<0){nh=24+nh;nd=-1;}t.h.value=nh;
nd=nd+td-n.getDate();if(nd<0){
x=n.getMonth();
if(x==0||x==2||x==4||x==6||x==7||x==9||x==11){nd=3 1+nd;}
if(x==3||x==5||x==8||x==10){nd=30+nd;}

if(x==1){if(n.getYear()/4-Math.floor(n.getYear()/4)==0){nd=29+nd;}else{nd=28
+nd;}}
}no=-1;t.d.value=nd;
no=no+to-n.getMonth();if(no<0){no=11+no;ny=-1;}t.o.value=no;

ny=ny+ty-n.getYear();if(ny<0){t.y.value=0;}else{t.y.value=n y;setTimeout("e()
",1000);}
}
}
</script>

Example:

http://members.cox.net/icystorm/retire

---------------
Joseph
ic************@hotnospammail.com

(Please remove both occurrences of "nospam" to reply via email, or simply
reply here in USENET instead.)

Jul 20 '05 #1
3 1408
"Joseph S" <no****@nospam.org> writes:
I am having problems with the following countdown script. For some reason,
the number of months is occasionally wrong. I can't quite put my finger on
the problem. Any assistance or recommendation from someone more knowlegable
than me would be appreciated. Thanks much.
Measuring difference in time in months is not well defined.
How many months and days are there between
2004-02-29 and 2004-05-31 (92 days)
or between
2004-03-01 and 2004-06-01 (also 92 days)
or even
2004-01-29 and 2004-02-29 (29 days)
and
2004-01-30 and 2004-03-01 (also 29 days)

If you can answer this in a way that you are satisfied with ... does your
program agree with you?
<script>


It's <script type="text/javascript">. The type attribute is required
in HTML 4.

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #2
JRS: In article <e2_Pb.12721$zy3.2450@okepread01>, seen in
news:comp.lang.javascript, Joseph S <no****@nospam.org> posted at Thu,
22 Jan 2004 18:37:49 :-
I am having problems with the following countdown script. For some reason,
the number of months is occasionally wrong. I can't quite put my finger on
the problem.


The code does what you have programmed it to do, but it is badly written
and your intent is concealed.

Obviously, though, you are not making effective use of the properties of
a date object. See sig at foot.

You have n.getYear()/4-Math.floor(n.getYear()/4)==0
which should probably be n.getYear()%4 == 0 except that you have no
need for that part of the code at all.
If this is course-work requiting you to use inefficient techniques in
order to exercise your programming skill, then you should say so.

If you have found the approach recommended in a book, except as above,
burn the book.

--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 ©
<URL:http://jibbering.com/faq/> Jim Ley's FAQ for news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
Jul 20 '05 #3
"Dr John Stockton" <sp**@merlyn.demon.co.uk> wrote:
news:comp.lang.javascript, Joseph S <no****@nospam.org> posted at Thu,
22 Jan 2004 18:37:49 :-
I am having problems with the following countdown script. For some reason,the number of months is occasionally wrong. I can't quite put my finger onthe problem.
The code does what you have programmed it to do, but it is badly written
and your intent is concealed.

Obviously, though, you are not making effective use of the properties of
a date object. See sig at foot.

You have n.getYear()/4-Math.floor(n.getYear()/4)==0
which should probably be n.getYear()%4 == 0 except that you have no
need for that part of the code at all.
If this is course-work requiting you to use inefficient techniques in
order to exercise your programming skill, then you should say so.


Nah. I'm just wasn't sure what I was doing. That's why I posted.
If you have found the approach recommended in a book, except as above,
burn the book.


Thanks for the free advice.

Joseph

Jul 20 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
3252
by: Matt Stanley | last post by:
I am using the countdown script developed by Chris Nott on his website(http://www.dithered.com/javascript/countdown/example.html). The script counts down the days, hours, minutes and seconds to a...
2
4702
by: Matthew | last post by:
Is there a javascript or alternative default fill friendly way for counting down the remaining characters left in a form box?
3
2673
by: Bonnett | last post by:
I have been creating a generic countdown timer (source code below), counting the seconds, minutes, hours and days till an event, but I have having trouble with it finding out how many hours are...
8
3732
by: Michael | last post by:
I have this script that works the way I want except for one thing... Once it hits zero it starts to count up and looks like this: -1:0-1:0-1:0-18 with the last number counting up. Can anyone...
5
1142
by: Supra | last post by:
i can't get countdown timer working in webform..... Private Sub btnStart_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStart.Click Dim rnd1 As New Random...
4
2144
by: petermichaux | last post by:
Hi, I'm hoping for a reason I'm wrong or an alternate solution... I'd like to be able to dynamically include some javascript files. This is like scriptaculous.js library but their solution is...
0
2349
by: Jorhajnes | last post by:
Hi there. Im very new to making games in flash, although I have used flash for quite some time now in web-based situations so I know my way around. Anyways, I thought it would be fun to try...
0
7108
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
6967
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
1
6847
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
1
4875
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4565
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3078
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1383
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
618
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
272
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.