<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Hi Matrix, in Software Archive</title>
    <link>https://community.intel.com/t5/Software-Archive/JavaScript-Date-wrong-result-when-using-XDK/m-p/1088375#M64379</link>
    <description>&lt;P&gt;Hi Matrix,&lt;/P&gt;

&lt;P&gt;It is the way the Javascript library is. In Javascript programming (and many other languages), array references used 0 based counting. So 0 is the index of the first item, etc. &amp;nbsp; As a side effect of that, the Date library is functioning as you discover. &lt;SPAN style="font-size: 13.008px; line-height: 19.512px;"&gt;Weirdly, days are numbered "normally".&lt;/SPAN&gt;&lt;/P&gt;

&lt;P&gt;&amp;nbsp;It is not a bug in the XDK or Javascript. It is merely a questionable design decision that was made a long time ago.&amp;nbsp;&lt;/P&gt;

&lt;P&gt;&lt;A href="http://stackoverflow.com/questions/1453043/zero-based-month-numbering" target="_blank"&gt;http://stackoverflow.com/questions/1453043/zero-based-month-numbering&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 14 Apr 2016 21:33:34 GMT</pubDate>
    <dc:creator>Chris_P_Intel</dc:creator>
    <dc:date>2016-04-14T21:33:34Z</dc:date>
    <item>
      <title>JavaScript Date() wrong result when using XDK.</title>
      <link>https://community.intel.com/t5/Software-Archive/JavaScript-Date-wrong-result-when-using-XDK/m-p/1088372#M64376</link>
      <description>&lt;P&gt;I found a very interesting JavaScript Date() wrong result when using XDK.&lt;/P&gt;

&lt;P&gt;Setting a Date in Date(year,month,day) format will add one more month on result.&lt;/P&gt;

&lt;P&gt;I am not sure it is only on XDK or Javascript itself. (It seems from the Javascript itself.)&lt;/P&gt;

&lt;P&gt;&lt;SPAN style="font-size: 13.008px; line-height: 19.512px;"&gt;The test code is as below for your test.&lt;/SPAN&gt;&lt;/P&gt;

&lt;PRE class="brush:jscript;"&gt;&amp;lt;!DOCTYPE html&amp;gt;
&amp;lt;html&amp;gt;
&amp;lt;body&amp;gt;

&amp;lt;p id="demo"&amp;gt;&amp;lt;/p&amp;gt;

&amp;lt;script&amp;gt;
var d1 = new Date("2016/01/01");
var d2 = new Date(2016,01,01);

document.getElementById("demo").innerHTML = 
"Date('2016/01/01') = "+d1
+"&amp;lt;br&amp;gt;It shows the right date.&amp;lt;br&amp;gt;"
+"&amp;lt;br&amp;gt;Date(2016,1,1) = "+d2+"&amp;lt;br&amp;gt;It will add one month to show the wrong date.";
&amp;lt;/script&amp;gt;

&amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;&lt;/PRE&gt;

&lt;P&gt;&lt;SPAN style="font-size: 13.008px; line-height: 19.512px;"&gt;/* You will get result as below ---------------------------------------------------------------&lt;/SPAN&gt;&lt;BR /&gt;
	Date('2016/01/01')=Fri Jan 01 2016 00:00:00 GMT+0800 (CST)&lt;BR /&gt;
	It shows the right date.&lt;BR /&gt;
	&lt;BR /&gt;
	Date(2016,1,1)=Mon Feb 01 2016 00:00:00 GMT+0800 (CST)&lt;BR /&gt;
	It will add one month to show the wrong date.&lt;BR /&gt;
	-----------------------------------------------------------------------------------------------------*/&lt;/P&gt;</description>
      <pubDate>Thu, 14 Apr 2016 04:13:15 GMT</pubDate>
      <guid>https://community.intel.com/t5/Software-Archive/JavaScript-Date-wrong-result-when-using-XDK/m-p/1088372#M64376</guid>
      <dc:creator>Matrix_Lee</dc:creator>
      <dc:date>2016-04-14T04:13:15Z</dc:date>
    </item>
    <item>
      <title>Its likely because of the</title>
      <link>https://community.intel.com/t5/Software-Archive/JavaScript-Date-wrong-result-when-using-XDK/m-p/1088373#M64377</link>
      <description>&lt;P&gt;Its likely because of the following:&lt;/P&gt;

&lt;P&gt;&lt;SPAN style="font-size: 12px; line-height: 18px;"&gt;"2016/01/01" is already a "real date", so javascript wil (try to) convert the string date to a date object.&lt;/SPAN&gt;&lt;/P&gt;

&lt;P&gt;&lt;SPAN style="font-size: 12px; line-height: 18px;"&gt;Date(2016,1,1) wil make you a new date, with month zero based: 0 =Jan, 1 = Feb, 2 = March, 3 = April etc..&lt;/SPAN&gt;&lt;/P&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 14 Apr 2016 11:25:41 GMT</pubDate>
      <guid>https://community.intel.com/t5/Software-Archive/JavaScript-Date-wrong-result-when-using-XDK/m-p/1088373#M64377</guid>
      <dc:creator>Wesley_S_1</dc:creator>
      <dc:date>2016-04-14T11:25:41Z</dc:date>
    </item>
    <item>
      <title>Dear Wesley,</title>
      <link>https://community.intel.com/t5/Software-Archive/JavaScript-Date-wrong-result-when-using-XDK/m-p/1088374#M64378</link>
      <description>&lt;P&gt;Dear Wesley,&lt;/P&gt;

&lt;P&gt;Thank for your reply. You may be right in technically.&lt;/P&gt;

&lt;P&gt;But Month should start from one, right?&lt;/P&gt;

&lt;P&gt;It is wrong or right action of Javascript on XDK?&lt;BR /&gt;
	&lt;BR /&gt;
	Should Javascript or XDK need to improve it?&lt;/P&gt;

&lt;P&gt;Matrix&lt;/P&gt;</description>
      <pubDate>Thu, 14 Apr 2016 11:37:46 GMT</pubDate>
      <guid>https://community.intel.com/t5/Software-Archive/JavaScript-Date-wrong-result-when-using-XDK/m-p/1088374#M64378</guid>
      <dc:creator>Matrix_Lee</dc:creator>
      <dc:date>2016-04-14T11:37:46Z</dc:date>
    </item>
    <item>
      <title>Hi Matrix,</title>
      <link>https://community.intel.com/t5/Software-Archive/JavaScript-Date-wrong-result-when-using-XDK/m-p/1088375#M64379</link>
      <description>&lt;P&gt;Hi Matrix,&lt;/P&gt;

&lt;P&gt;It is the way the Javascript library is. In Javascript programming (and many other languages), array references used 0 based counting. So 0 is the index of the first item, etc. &amp;nbsp; As a side effect of that, the Date library is functioning as you discover. &lt;SPAN style="font-size: 13.008px; line-height: 19.512px;"&gt;Weirdly, days are numbered "normally".&lt;/SPAN&gt;&lt;/P&gt;

&lt;P&gt;&amp;nbsp;It is not a bug in the XDK or Javascript. It is merely a questionable design decision that was made a long time ago.&amp;nbsp;&lt;/P&gt;

&lt;P&gt;&lt;A href="http://stackoverflow.com/questions/1453043/zero-based-month-numbering" target="_blank"&gt;http://stackoverflow.com/questions/1453043/zero-based-month-numbering&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 14 Apr 2016 21:33:34 GMT</pubDate>
      <guid>https://community.intel.com/t5/Software-Archive/JavaScript-Date-wrong-result-when-using-XDK/m-p/1088375#M64379</guid>
      <dc:creator>Chris_P_Intel</dc:creator>
      <dc:date>2016-04-14T21:33:34Z</dc:date>
    </item>
    <item>
      <title>When you titled this forum</title>
      <link>https://community.intel.com/t5/Software-Archive/JavaScript-Date-wrong-result-when-using-XDK/m-p/1088376#M64380</link>
      <description>&lt;P&gt;When you titled this forum thread you named it "JavaScript Date() wrong result when using XDK." &amp;nbsp; &amp;nbsp;&lt;BR /&gt;
	&lt;BR /&gt;
	But did you actually compare it to any other Javascript installations, like in Chrome or Firefox or Node?&lt;/P&gt;</description>
      <pubDate>Thu, 14 Apr 2016 21:36:29 GMT</pubDate>
      <guid>https://community.intel.com/t5/Software-Archive/JavaScript-Date-wrong-result-when-using-XDK/m-p/1088376#M64380</guid>
      <dc:creator>Chris_P_Intel</dc:creator>
      <dc:date>2016-04-14T21:36:29Z</dc:date>
    </item>
    <item>
      <title>Dear Chris,</title>
      <link>https://community.intel.com/t5/Software-Archive/JavaScript-Date-wrong-result-when-using-XDK/m-p/1088377#M64381</link>
      <description>&lt;P&gt;Dear Chris,&lt;/P&gt;

&lt;P&gt;Yes, just trying on Chrome, Firefox and Safiri.&lt;/P&gt;

&lt;P&gt;There are all have the same problem.&lt;/P&gt;

&lt;P&gt;Just as your saying, it is not consistency in the rules of month and day.&lt;/P&gt;

&lt;P&gt;May be it is time to suggest Javascript to refine.&lt;BR /&gt;
	&lt;BR /&gt;
	And Date() is not convenient to do compare operation like DateA&amp;gt;DateB, may be XDK can build a JS Dates library to improve all these problems.&lt;BR /&gt;
	&lt;BR /&gt;
	The Date() comparison method could like below for reference.&lt;/P&gt;

&lt;PRE class="brush:jscript;" style="margin-top: 0px; margin-bottom: 1em; padding: 5px; border: 0px; font-size: 13px; width: auto; max-height: 600px; overflow: auto; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, sans-serif; color: rgb(57, 51, 24); word-wrap: normal; background-color: rgb(238, 238, 238);"&gt;
// Source: &lt;A href="http://stackoverflow.com/questions/497790" target="_blank"&gt;http://stackoverflow.com/questions/497790&lt;/A&gt;
var dates = {
    convert:function(d) {
        // Converts the date in d to a date-object. The input can be:
        //   a date object: returned without modification
        //  an array      : Interpreted as [year,month,day]. NOTE: month is 0-11.
        //   a number     : Interpreted as number of milliseconds
        //                  since 1 Jan 1970 (a timestamp) 
        //   a string     : Any format supported by the javascript engine, like
        //                  "YYYY/MM/DD", "MM/DD/YYYY", "Jan 31 2009" etc.
        //  an object     : Interpreted as an object with year, month and date
        //                  attributes.  **NOTE** month is 0-11.
        return (
            d.constructor === Date ? d :
            d.constructor === Array ? new Date(d[0],d[1],d[2]) :
            d.constructor === Number ? new Date(d) :
            d.constructor === String ? new Date(d) :
            typeof d === "object" ? new Date(d.year,d.month,d.date) :
            NaN
        );
    },
    compare:function(a,b) {
        // Compare two dates (could be of any type supported by the convert
        // function above) and returns:
        //  -1 : if a &amp;lt; b
        //   0 : if a = b
        //   1 : if a &amp;gt; b
        // NaN : if a or b is an illegal date
        // NOTE: The code inside isFinite does an assignment (=).
        return (
            isFinite(a=this.convert(a).valueOf()) &amp;amp;&amp;amp;
            isFinite(b=this.convert(b).valueOf()) ?
            (a&amp;gt;b)-(a&amp;lt;b) :
            NaN
        );
    },
    inRange:function(d,start,end) {
        // Checks if date in d is between dates in start and end.
        // Returns a boolean or NaN:
        //    true  : if d is between start and end (inclusive)
        //    false : if d is before start or after end
        //    NaN   : if one or more of the dates is illegal.
        // NOTE: The code inside isFinite does an assignment (=).
       return (
            isFinite(d=this.convert(d).valueOf()) &amp;amp;&amp;amp;
            isFinite(start=this.convert(start).valueOf()) &amp;amp;&amp;amp;
            isFinite(end=this.convert(end).valueOf()) ?
            start &amp;lt;= d &amp;amp;&amp;amp; d &amp;lt;= end :
            NaN
        );
    }
}

&lt;/PRE&gt;</description>
      <pubDate>Thu, 14 Apr 2016 23:00:00 GMT</pubDate>
      <guid>https://community.intel.com/t5/Software-Archive/JavaScript-Date-wrong-result-when-using-XDK/m-p/1088377#M64381</guid>
      <dc:creator>Matrix_Lee</dc:creator>
      <dc:date>2016-04-14T23:00:00Z</dc:date>
    </item>
  </channel>
</rss>

