By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,466 Members | 1,130 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,466 IT Pros & Developers. It's quick & easy.

FAO Robert: Why won't this code work part 2

P: n/a
Ok....I made the appropriate additions to the spaces commented and this is
what I got now:

currentDate = new Date;
today =
currentDate.getDate()+"/"+currentDate.getMonth()+"/"+currentDate.getYear();
cookie = sharedObject.getLocal("date");
if (cookie.data.expire == undefined) {
cookie.data.expire =
(currentDate.getDate()+7)+"/"+currentDate.getMonth()+"/"+currentDate.getYear
();
cookie.data.today = today;
} else {
sepToday = cookie.data.today.split("/");
sepExpire = cookie.data.expire.split("/");
if (Number(sepToday[0]) >= Number(sepExpire[0]) && Number(sepToday[1]) <=
Number(sepExpire[1])) {
this.stop(); //stay stopped on frame 1
} else {
this.gotoAndPlay(2); //Play movie
}
}
cookie.flush();

How can I test it?
I mean....I tried searching for a file called date.sol here but couldn't
find it.
Is there a way I can sort of reset the system to test the script's
functionality?
And to change the expiration period I understand I need to change the number
here:
currentDate.getDate()+7
Am I correct?

Thanks in advance for your big help :)

FayeC
Jul 23 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
JRS: In article <Kp****************@read1.cgocable.net>, dated Sun, 5
Sep 2004 11:38:18, seen in news:comp.lang.javascript, FayeC
<fa**********@cogeco.ca> posted :
Ok....I made the appropriate additions to the spaces commented and this is
what I got now:

currentDate = new Date;
Should be new Date() , although your version may work.
today =
currentDate.getDate()+"/"+currentDate.getMonth()+"/"+currentDate.getYear();
Wrong month, see via FAQ. As an apparent Canadian, you should have
noticed that D/M/Y, though moderately logical, is often
indistinguishable from M/D/Y which your neighbours like.
cookie = sharedObject.getLocal("date");
if (cookie.data.expire == undefined) {
cookie.data.expire =
(currentDate.getDate()+7)+"/"+currentDate.getMonth()+"/"+currentDate.getYear
();
Gives non-existent date if today is in the last 7 days of the month; I
know no reason to expect that to be acceptable. Can give non-existent
month.
cookie.data.today = today;
} else {
sepToday = cookie.data.today.split("/");
sepExpire = cookie.data.expire.split("/");
if (Number(sepToday[0]) >= Number(sepExpire[0]) && Number(sepToday[1]) <=
Number(sepExpire[1])) {
this.stop(); //stay stopped on frame 1
} else {
this.gotoAndPlay(2); //Play movie
}
}


Looks as if it may fail around year-end. See below.

--
John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4
<URL:http://www.jibbering.com/faq/> JL/RC: FAQ of 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 23 '05 #2

P: n/a
In article <oN**************@merlyn.demon.co.uk>, Dr John Stockton
<sp**@merlyn.demon.co.uk> writes
JRS: In article <Kp****************@read1.cgocable.net>, dated Sun, 5
Sep 2004 11:38:18, seen in news:comp.lang.javascript, FayeC
<fa**********@cogeco.ca> posted :
Ok....I made the appropriate additions to the spaces commented and this is
what I got now:

currentDate = new Date;


Should be new Date() , although your version may work.

<snip>

Both new Date and new Date() are valid and mean the same thing.

John
--
John Harris
Jul 23 '05 #3

P: n/a
John G Harris wrote:
In article <oN**************@merlyn.demon.co.uk>, Dr John Stockton
<sp**@merlyn.demon.co.uk> writes
JRS: In article <Kp****************@read1.cgocable.net>, dated Sun, 5
Sep 2004 11:38:18, seen in news:comp.lang.javascript, FayeC
<fa**********@cogeco.ca> posted :
Ok....I made the appropriate additions to the spaces commented and this is
what I got now:

currentDate = new Date;


Should be new Date() , although your version may work.


<snip>

Both new Date and new Date() are valid and mean the same thing.


2 Questions:

1) Is that documented anywhere?
2) How do you pass parameters to new Date() if you don't use the ()?
--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq
Jul 23 '05 #4

P: n/a
Randy Webb <Hi************@aol.com> writes:
John G Harris wrote:
Both new Date and new Date() are valid and mean the same thing.
2 Questions:

1) Is that documented anywhere?


ECMA 262 v3 section 11.2.
The production is:

<LeftHandSideExpression> -> <NewExpression>
-> new <NewExpression>
-> new <MemberExpression>
-> new <PrimaryExpression>
-> new <Identifier>
-> new Date

The evaluation is according to section 11.2.2. First we evaluate the
identifier "Date", giving an object which has a [[Construct]] method.
Then that method is called providing no arguments.

You can trace <LeftHandSideExpression> back to something that is a
valid right hand side as well :)

It's documented for JScript on MSDN:
<URL:http://msdn.microsoft.com/library/default.asp?url=/library/en-us/script56/html/js56jsoprnew.asp>

It works like this in JavaScript 1.0 in Nescape 2, so it's a good
bet it has worked in most browsers since then.
2) How do you pass parameters to new Date() if you don't use the ()?


How do you pass parameters to "new Date()" when you don't specify any
parameters? :)

Omitting the parentheses means that the constructor is called with
no parameters, just as using parentheses with no arguments inside them.

/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 23 '05 #5

P: n/a
Randy Webb wrote:
John G Harris wrote:
Dr John Stockton writes:
FayeC posted :
Ok....I made the appropriate additions to the spaces commented and
this is what I got now:

currentDate = new Date;

Should be new Date() , although your version may work.
<snip>

Both new Date and new Date() are valid and mean the same thing.


2 Questions:

1) Is that documented anywhere?


ECMA 262 (3rd edition) section 11.2, particularly the first algorithm in
section 11.2.2 (production == NewExpression: new NewExpression). Where
if the operand of the new operator is evaluated and the internal
GetValue function applied to the result returns an Object with a
[[Construct]] method (so a function object), its [[Construct]] method is
called with no arguments.
2) How do you pass parameters to new Date() if you don't use the ()?


Arguments are only passed to the [[construct]] method in the second
algorithm in section 11.2.2 (production == MemberExpression: new
MemberExpression Arguments).

However, knowing that I can use the - new - operator without any
parenthesise in javascript if arguments are not needed, doesn't
encourage me to do so.

Richard.
Jul 23 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.