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

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • FayeC

    #1

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

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

    currentDate = new Date;
    today =
    currentDate.get Date()+"/"+currentDate.g etMonth()+"/"+currentDate.g etYear();
    cookie = sharedObject.ge tLocal("date");
    if (cookie.data.ex pire == undefined) {
    cookie.data.exp ire =
    (currentDate.ge tDate()+7)+"/"+currentDate.g etMonth()+"/"+currentDate.g etYear
    ();
    cookie.data.tod ay = today;
    } else {
    sepToday = cookie.data.tod ay.split("/");
    sepExpire = cookie.data.exp ire.split("/");
    if (Number(sepToda y[0]) >= Number(sepExpir e[0]) && Number(sepToday[1]) <=
    Number(sepExpir e[1])) {
    this.stop(); //stay stopped on frame 1
    } else {
    this.gotoAndPla y(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.get Date()+7
    Am I correct?

    Thanks in advance for your big help :)

    FayeC


  • Dr John Stockton

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

    JRS: In article <KpG_c.14462$0c .854@read1.cgoc able.net>, dated Sun, 5
    Sep 2004 11:38:18, seen in news:comp.lang. javascript, FayeC
    <fayec_nospam@c ogeco.ca> posted :[color=blue]
    >Ok....I made the appropriate additions to the spaces commented and this is
    >what I got now:
    >
    >currentDate = new Date;[/color]

    Should be new Date() , although your version may work.
    [color=blue]
    >today =
    >currentDate.ge tDate()+"/"+currentDate.g etMonth()+"/"+currentDate.g etYear();[/color]

    Wrong month, see via FAQ. As an apparent Canadian, you should have
    noticed that D/M/Y, though moderately logical, is often
    indistinguishab le from M/D/Y which your neighbours like.
    [color=blue]
    >cookie = sharedObject.ge tLocal("date");
    > if (cookie.data.ex pire == undefined) {
    > cookie.data.exp ire =
    >(currentDate.g etDate()+7)+"/"+currentDate.g etMonth()+"/"+currentDate.g etYear
    >();[/color]

    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.
    [color=blue]
    > cookie.data.tod ay = today;
    > } else {
    > sepToday = cookie.data.tod ay.split("/");
    > sepExpire = cookie.data.exp ire.split("/");
    > if (Number(sepToda y[0]) >= Number(sepExpir e[0]) && Number(sepToday[1]) <=
    >Number(sepExpi re[1])) {
    > this.stop(); //stay stopped on frame 1
    > } else {
    > this.gotoAndPla y(2); //Play movie
    > }
    > }[/color]

    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.c om/faq/> JL/RC: FAQ of news:comp.lang. javascript
    <URL:http://www.merlyn.demo n.co.uk/js-index.htm> jscr maths, dates, sources.
    <URL:http://www.merlyn.demo n.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.

    Comment

    • John G Harris

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

      In article <oNEmfHCA50OBFw rQ@merlyn.demon .co.uk>, Dr John Stockton
      <spam@merlyn.de mon.co.uk> writes[color=blue]
      >JRS: In article <KpG_c.14462$0c .854@read1.cgoc able.net>, dated Sun, 5
      >Sep 2004 11:38:18, seen in news:comp.lang. javascript, FayeC
      ><fayec_nospam@ cogeco.ca> posted :[color=green]
      >>Ok....I made the appropriate additions to the spaces commented and this is
      >>what I got now:
      >>
      >>currentDate = new Date;[/color]
      >
      >Should be new Date() , although your version may work.[/color]
      <snip>

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

      John
      --
      John Harris

      Comment

      • Randy Webb

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

        John G Harris wrote:
        [color=blue]
        > In article <oNEmfHCA50OBFw rQ@merlyn.demon .co.uk>, Dr John Stockton
        > <spam@merlyn.de mon.co.uk> writes
        >[color=green]
        >>JRS: In article <KpG_c.14462$0c .854@read1.cgoc able.net>, dated Sun, 5
        >>Sep 2004 11:38:18, seen in news:comp.lang. javascript, FayeC
        >><fayec_nospam @cogeco.ca> posted :
        >>[color=darkred]
        >>>Ok....I made the appropriate additions to the spaces commented and this is
        >>>what I got now:
        >>>
        >>>currentDat e = new Date;[/color]
        >>
        >>Should be new Date() , although your version may work.[/color]
        >
        > <snip>
        >
        > Both new Date and new Date() are valid and mean the same thing.[/color]

        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.javas cript FAQ - http://jibbering.com/faq

        Comment

        • Lasse Reichstein Nielsen

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

          Randy Webb <HikksNotAtHome @aol.com> writes:
          [color=blue]
          > John G Harris wrote:[color=green]
          >> Both new Date and new Date() are valid and mean the same thing.[/color]
          >
          > 2 Questions:
          >
          > 1) Is that documented anywhere?[/color]

          ECMA 262 v3 section 11.2.
          The production is:

          <LeftHandSideEx pression> -> <NewExpressio n>
          -> new <NewExpressio n>
          -> new <MemberExpressi on>
          -> new <PrimaryExpress ion>
          -> 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 <LeftHandSideEx pression> 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.as p>

          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.
          [color=blue]
          > 2) How do you pass parameters to new Date() if you don't use the ()?[/color]

          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 - lrn@hotpop.com
          DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html>
          'Faith without judgement merely degrades the spirit divine.'

          Comment

          • Richard Cornford

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

            Randy Webb wrote:[color=blue]
            > John G Harris wrote:[color=green]
            >> Dr John Stockton writes:[color=darkred]
            >>>FayeC posted :
            >>>>Ok....I made the appropriate additions to the spaces commented and
            >>>>this is what I got now:
            >>>>
            >>>>currentDa te = new Date;
            >>>
            >>>Should be new Date() , although your version may work.[/color]
            >>
            >> <snip>
            >>
            >> Both new Date and new Date() are valid and mean the same thing.[/color]
            >
            > 2 Questions:
            >
            > 1) Is that documented anywhere?[/color]

            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.
            [color=blue]
            > 2) How do you pass parameters to new Date() if you don't use the ()?[/color]

            Arguments are only passed to the [[construct]] method in the second
            algorithm in section 11.2.2 (production == MemberExpressio n: new
            MemberExpressio n 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.


            Comment

            Working...