Date in Opera 9.50

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Dr J R Stockton

    #1

    Date in Opera 9.50


    In Opera 9.2x, new Date.getYear() gives 108.
    In Opera 9.50, new Date.getYear() gives 2008.
    AIUI, IIRC, etc., ECMA & ISO/IEC require Year-1900.
    9.2x was right, 9.50 agrees with IE 6 & 7.

    Do we agree? Anything else interesting noticed?

    --
    (c) John Stockton, nr London, UK. ?@merlyn.demon. co.uk Turnpike v6.05.
    Web <URL:http://www.merlyn.demo n.co.uk/- w. FAQish topics, links, acronyms
    PAS EXE etc : <URL:http://www.merlyn.demo n.co.uk/programs/- see 00index.htm
    Dates - miscdate.htm moredate.htm js-dates.htm pas-time.htm critdate.htm etc.
  • Lasse Reichstein Nielsen

    #2
    Re: Date in Opera 9.50

    Dr J R Stockton <jrs@merlyn.dem on.co.ukwrites:
    In Opera 9.2x, new Date.getYear() gives 108.
    In Opera 9.50, new Date.getYear() gives 2008.
    AIUI, IIRC, etc., ECMA & ISO/IEC require Year-1900.
    9.2x was right, 9.50 agrees with IE 6 & 7.
    >
    Do we agree?
    The getYear method is not part of ECMAScript proper, but is specified
    in the non-normative Annex B (B.2.4 to be exact). I.e., it's a
    *suggested* implementation for compatability reasons, but not
    required.
    In practice, agreeing with IE is probably a better compatability
    choice.
    Anything else interesting noticed?
    Nothing so far. The typical bugs in Array.prototype .sort, but everybody
    has those :)

    /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

    • dhtml

      #3
      Re: Date in Opera 9.50

      On Jun 17, 1:13 pm, Lasse Reichstein Nielsen <l...@hotpop.co mwrote:
      Dr J R Stockton <j...@merlyn.de mon.co.ukwrites :
      >
      [snip]
      >
      Anything else interesting noticed?
      >
      Nothing so far. The typical bugs in Array.prototype .sort, but everybody
      has those :)
      >
      Can you elaborate on that?

      Garrett
      /L

      Comment

      • Lasse Reichstein Nielsen

        #4
        Re: Date in Opera 9.50

        dhtml <dhtmlkitchen@g mail.comwrites:
        On Jun 17, 1:13 pm, Lasse Reichstein Nielsen <l...@hotpop.co mwrote:
        >Nothing so far. The typical bugs in Array.prototype .sort, but everybody
        >has those :)
        >>
        >
        Can you elaborate on that?
        Array.prototype .sort's default comparison is required to sort the
        array elements so that the "undefined" value is greater than all
        other values, but less than no value at all. I.e., if the array
        doesn't have a value at an index at all (as opposted to having
        a value that is undefined), then the sorted array will too, and
        it will have those at the end.

        Or, to quote 15.4.4.11:

        There must be some mathematical permutation p of the nonnegative
        integers less than Result(2), such that for every nonnegative integer
        j less than Result(2), if property old[j] existed, then new[p(j)] is
        exactly the same value as old[j],. but if property old[j] did not
        exist, then new[p(j)] does not exist.

        Then for all nonnegative integers j and k, each less than Result(2),
        if SortCompare(j,k )<0 (see SortCompare below), then p(j)< p(k).

        and SortCompare(j,k ) (where j and k are indices) is defined as:

        1. Call ToString(j).
        2. Call ToString(k).
        3. If this object does not have a property named by Result(1), and this object does not have a
        property named by Result(2), return +0.
        4. If this object does not have a property named by Result(1), return 1.
        5. If this object does not have a property named by Result(2), return -1.
        6. Call the [[Get]] method of this object with argument Result(1).
        7. Call the [[Get]] method of this object with argument Result(2).
        8. Let x be Result(6).
        9. Let y be Result(7).
        10. If x and y are both undefined,retur n +0.
        11. If x is undefined,retur n 1.
        12. If y is undefined,retur n -1.
        13. If the argument comparefn is undefined, goto step 16.
        14. Call comparefn with arguments x and y.
        15. Return Result(14).
        16. Call ToString(x).
        17. Call ToString(y).
        18. If Result(16) < Result(17), return -1.
        19. If Result(16) Result(17), return 1.
        20. Return +0.

        I.e., step 3..5 means that missing properties are sorted last,
        step 6..12 means that undefined are sorted just before those,
        and for all other values, their string representation is compared.

        Example: The array:
        var a = [42,NaN,0,"",,fa lse,undefined,n ull,,true]
        has a length of 10, but only 9 elements. The expressions
        (4 in a)
        and
        (8 in a)
        both evaluate to false.
        Sorting it using
        a.sort()
        should give the equivalent of
        ["",0,42,NaN,fal se,null,true,un defined,,,]

        Try the following in different browsers:
        var a = [42,NaN,0,"",,fa lse,undefined,n ull,,true]
        a.sort();
        function prettyArray(arr ) {
        var res = [];
        res.length = arr.length;
        for(var i = 0; i < arr.length; i++) {
        if (i in arr) {
        var pretty;
        if (typeof arr[i] == "string") {
        res[i] = '"' + arr[i] + '"';
        } else {
        res[i] = String(arr[i]);
        }
        }
        }
        if (!((arr.length-1) in arr)) { res.length++; }
        return "[" + res.join(",") + "]";
        }
        alert(prettyArr ay(a));


        In Opera, one of the missing elements is converted to an existing
        element with value "undefined" :
        alert(8 in a); // Opera: true!
        In Firefox 3, both missing elements are converted to undefined values:
        alert(8 in a); // FF3: true!
        alert(9 in a); // FF3: true!
        IE 7 actually removes the undefined value:
        alert(7 in a); // IE7: false!
        (It doesn't help that IE fails to ignore a final comma in array literals:
        [42,].length == 2 // IE7. Should be 1
        )

        Safari actually appears to sort it correctly.
        /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

        • Dr J R Stockton

          #5
          Re: Date in Opera 9.50

          In comp.lang.javas cript message <7icn4y62.fsf@h otpop.com>, Tue, 17 Jun
          2008 22:13:57, Lasse Reichstein Nielsen <lrn@hotpop.com posted:
          ^^^^^^^^^^^^^^

          A non-working address there is forgivable, except by the obnoxious; but
          it should not be repeated in the signature.
          >Dr J R Stockton <jrs@merlyn.dem on.co.ukwrites:
          >Anything else interesting noticed?
          Call new Date(Y, M, D) still is limited to four-digit years.

          In new Date("1970/01/01 EST") EST is still ignored.

          Ctrl-Alt-V no longer validates via w3, alas, at least by default.


          Firefox 3 has fixed the Date.UTC(Y,M,D) D<=0 error; it was treated
          before as D=1. And its time resolution of new Date() seems to be
          better, 1 ms rather than 15.625 - that needs checking..

          --
          (c) John Stockton, nr London, UK. ?@merlyn.demon. co.uk Turnpike v6.05 MIME.
          Web <URL:http://www.merlyn.demo n.co.uk/- FAQqish topics, acronyms & links;
          Astro stuff via astron-1.htm, gravity0.htm ; quotings.htm, pascal.htm, etc.
          No Encoding. Quotes before replies. Snip well. Write clearly. Don't Mail News.

          Comment

          • dhtml

            #6
            Re: Date in Opera 9.50

            On Jun 18, 1:04 am, Lasse Reichstein Nielsen <l...@hotpop.co mwrote:
            dhtml <dhtmlkitc...@g mail.comwrites:
            On Jun 17, 1:13 pm, Lasse Reichstein Nielsen <l...@hotpop.co mwrote:
            Nothing so far. The typical bugs in Array.prototype .sort, but everybody
            has those :)
            >
            Can you elaborate on that?
            >
            Array.prototype .sort's default comparison is required to sort the
            array elements so that the "undefined" value is greater than all
            other values, but less than no value at all. I.e., if the array
            doesn't have a value at an index at all (as opposted to having
            a value that is undefined), then the sorted array will too, and
            it will have those at the end.
            >
            [snip]

            [snip]
            In Opera, one of the missing elements is converted to an existing
            element with value "undefined" :
              alert(8 in a); // Opera: true!
            In Firefox 3, both missing elements are converted to undefined values:
              alert(8 in a); // FF3: true!
              alert(9 in a); // FF3: true!
            IE 7 actually removes the undefined value:
              alert(7 in a); // IE7: false!
            (It doesn't help that IE fails to ignore a final comma in array literals:
              [42,].length == 2 // IE7. Should be 1
            )
            >
            Multi-line copy-paste, select example, and GO:
            javascript:void (eval("(functio n(){"
            + (document.selec tion&& document.select ion.createRange &&
            document.select ion.createRange ().text || window.getSelec tion())
            +"})()"));

            Pretty bad for sort to be adding/removing properties.

            It's not just sort(), though.

            javascript:aler t('0'in [,].concat()); // true in Opera, FF2
            javascript:aler t('0'in [,]); // true in FF2, false in Opera.

            I thought the When encountering a trailing comma, IE interprets that
            as an Elision. IOW, when IE sees - ElementList, - IE instead
            interprets it as the source text - ElementList,Eli sion - or -
            ElementList,, - should be interpreted.

            javascript:aler t("1"in[,]); // false in IE.

            But:
            javascript:aler t([,].length); // 2 in IE.

            Should be 1.

            Although the ES3 deviations doc is not quite right:-

            "2.6 Array Initialiser: §11.1.4
            Trailing commas in array literals add to the length, but they
            shouldn't. JScript treats the empty element after the trailing comma
            as undefined."


            That's not actually what JScript does. JScript treats it as an
            Elision.

            Garrett
            Safari actually appears to sort it correctly.
            Safari's not doing too bad.
            /L

            Comment

            Working...