NaN

R

RobG

No takers? :D

Apparently not. It doesn't "work" in Firefox either, I get a server
time of 23:59:50 on 31 December, 1970 when the page loads. I also get
a message saying "You have no new emails as of 01:11:39 AM
06/04/2007".

The loading animation seems pointless - after it displays for several
seconds, I still have to wait for the rest of the page to display.
That kind of page loading style was ditched in the 90's, there's a
reason why browsers show pages as the HTML arrives - it's what users
want. Good page authors have worked out how to code pages so that
they are displayed quickly with correct layout from the start.

The animated stuff is annoying as hell. Most people don't care what
the "server time" is (of what possible use is it?) and don't need a
local clock either. If they want one, they'll have it in their menu
bar (or some other handy position) already.

The date display seems odd - 06/04/2007 indicates 6 April 2007 to me.

The script seems unnecessarily long, e.g. the "DaysInMonth" function
can be re-written as:

function daysInMonth(month, year) {
return (new Date(year, month, 0)).getDate();
}

where month is jan=1, feb=2, etc. It may not suit all browsers that
you wish to support.

But it isn't needed anyway, follow JRS's link to read about dates and
clocks.
 
P

Phat G5 (G3)

Whoever write that code should have learned Javascript and read the
newsgroup FAQ (with care) first.

That script is a consolidation of 2 different scripts out on the net. I went
thru it and deleted a bunch of crap that was old. It started working and so
I have to stop and get onto more crucial parts and come back to it later on.
What specifically from the faq are you referring to? What really makes it
all that bad?

-S
 
P

Phat G5 (G3)

Phat G5 (G3) said the following on 6/4/2007 12:39 PM:
That script is a consolidation of 2 different scripts out on the net.

Most of what you find "on the net" isn't worth copying though.
I went thru it and deleted a bunch of crap that was old.

Then why is there a branch for a browser that is so outdated that it is
a pain to even find the last version of it? (Netscape 4). Typically, if
you see code that has if(document.layers) then you can rest assured it
is 10 years old or so.
It started working and so I have to stop and get onto
more crucial parts and come back to it later on.

As long as its a goal to get it updated, more efficient and quicker,
then there is nothing wrong with it.
What specifically from the faq are you referring to? What really makes it
all that bad?

The first thing I do when looking at code from the web is do a search
for the word "eval" and typically if you find it then it isn't very well
written. And it is true in this case. In the displayTime function you
have this code:

else if (document.layers)
{
var x = eval('document.layers.'+ obj);

var xWithoutEval = document.layers[obj];

//code here
}
else if (document.all)
{
var x = eval(obj)

var xWithoutEval = document.all[obj];

//code here

The advantage is that you aren't calling eval which starts a separate
instance of the compiler/engine and makes it more efficient. The other
problem with eavl(obj) is that it depends on a flaw in IE where it makes
the ID/NAME attribute a global variable and if a browser exists that
takes the document.all branch that doesn't make it a Global then it will
error out when that error can be easily avoided.

The function daysInMonth has this code:
if (WhichMonth == "Feb" && (WhichYear/4) != Math.floor(WhichYear/4))
DaysInMonth = 28;
if (WhichMonth == "Feb" && (WhichYear/4) == Math.floor(WhichYear/4))
DaysInMonth = 29;

The problem with that code will manifest itself every 400 years as leap
year is not a simple matter of dividing by 4, every 400 years there is
no leap day (test it for 2000).

John also won't like your date format or the fact that you used AM/PM
instead of a 24 hour clock.

There is probably more but I got tired of looking.
Randy,

Thank you for taking the time to respond with more than to just read the
faq. I had completely forgotten the issues with the document.layers[xxx].
That was a good flashback. I'll be taking all that out anyway. The browsers
that will be using this will support the document.getElementById() so that
should be fine. I'll make those other changes and work on it some more and
then post back for a better idea.

On another note... What exactly is the best way to calculate whether or not
it is a leap year via js?

Thanks,
-S
 
D

Dr J R Stockton

In comp.lang.javascript message said:
The problem with that code will manifest itself every 400 years as leap
year is not a simple matter of dividing by 4, every 400 years there is
no leap day (test it for 2000).


Your memory is failing, or is failing to update. It was 1900 when there
was last a missing February 29th, which is the cause of some uncertainty
concerning the natal year of Frederic of Penzance.

Y = 2000
M = 2
z = new Date(Date.UTC(Y, M, 0)).getUTCDate()

IIRC, the final Feb 29 of a millennium is alternately Tuesday & Friday.

While on the subject, more or less, of Opera :

Query - <URL:http://www.merlyn.demon.co.uk/estrdate.htm#CD> has a
button, "Pop Code Up". That's been OK in IE & FF, but in my Opera 9.21
the first 5 or so characters of the written string, which should start
"<pre>\n", are usually corrupted (they appear as random foreign, and the
<pre> is of course destroyed).

The actual code is in function PopThis(btn) in include1.js line
Wndw.document.write("<pre>\n", SafeHTML(Obj.Str), "\n<\/pre>")
and if I add a few spaces at the start of the first string the
corruption appears but does no real harm.

Do others see that in Opera?
 
L

-Lost

Dr said:
Your memory is failing, or is failing to update. It was 1900 when there
was last a missing February 29th, which is the cause of some uncertainty
concerning the natal year of Frederic of Penzance.

Y = 2000
M = 2
z = new Date(Date.UTC(Y, M, 0)).getUTCDate()

IIRC, the final Feb 29 of a millennium is alternately Tuesday & Friday.

While on the subject, more or less, of Opera :

Query - <URL:http://www.merlyn.demon.co.uk/estrdate.htm#CD> has a
button, "Pop Code Up". That's been OK in IE & FF, but in my Opera 9.21
the first 5 or so characters of the written string, which should start
"<pre>\n", are usually corrupted (they appear as random foreign, and the
<pre> is of course destroyed).

The actual code is in function PopThis(btn) in include1.js line
Wndw.document.write("<pre>\n", SafeHTML(Obj.Str), "\n<\/pre>")
and if I add a few spaces at the start of the first string the
corruption appears but does no real harm.

Do others see that in Opera?

Yep. Upon several presses it went from garbled to Asian characters.
Not sure if this will stay as is (I am going to send as UTF-8), but here
was one instance: "櫰ǬŸ’>."
 
D

Dr J R Stockton

Mon said:
On another note... What exactly is the best way to calculate whether or not
it is a leap year via js?

That is very rarely needed - it's not needed for date validation, for
example.

But it can be determined by
!new Date(y, 1, 366).getMonth()
or !!(!(y%4) ^ !(y%100) ^ !(y%400))
or !( y & 3 || y & 15 && !(y % 25) )
or by many other ways which you could have found via the FAQ.

It's a good idea to read the newsgroup c.l.j and its FAQ. See below.
 
D

Dr J R Stockton

In comp.lang.javascript message <84KdnT5GVLSYP_jbnZ2dnUVZ_uKknZ2d@comcas
Yep. Upon several presses it went from garbled to Asian characters.
Not sure if this will stay as is (I am going to send as UTF-8), but
here was one instance: "??Ÿ’>."

I think "non-Ascii" is more accurate than Asian; I think I've seen Maths
there. Random, no doubt.

Thanks. I've reported it to Opera.

Frederic : <URL:http://www.merlyn.demon.co.uk/leapyear.htm#TPoP>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,160
Messages
2,570,889
Members
47,423
Latest member
henerygril

Latest Threads

Top