diff --git a/bi/core.js b/bi/core.js index 8d24e0f0e..494b9d052 100644 --- a/bi/core.js +++ b/bi/core.js @@ -6249,7 +6249,6 @@ Date._QN = ["", BI.i18nText("BI-Quarter_1"), BI.i18nText("BI-Quarter_4")]; - /** Adds the number of days array to the Date object. */ Date._MD = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]; @@ -6284,12 +6283,19 @@ Date.prototype.getDayOfYear = function () { /** Returns the number of the week in year, as defined in ISO 8601. */ Date.prototype.getWeekNumber = function () { var d = new Date(this.getFullYear(), this.getMonth(), this.getDate(), 0, 0, 0); - var DoW = d.getDay(); - d.setDate(d.getDate() - (DoW + 6) % 7 + 3); // Nearest Thu + var week = d.getDay(); + if (this.getMonth() === 0 && this.getDate() <= week) { + return 1; + } + d.setDate(this.getDate() - week); var ms = d.valueOf(); // GMT d.setMonth(0); - d.setDate(4); // Thu in Week 1 - return Math.round((ms - d.valueOf()) / (7 * 864e5)) + 1; + d.setDate(1); + var offset = Math.floor((ms - d.valueOf()) / (7 * 864e5)) + 1; + if (d.getDay() > 0) { + offset++; + } + return offset; }; //离当前时间多少天的时间 @@ -6381,7 +6387,7 @@ Date.prototype.getOffsetMonth = function (n) { var dt = new Date(this.getTime()); var day = dt.getDate(); var monthDay = new Date(dt.getFullYear(), dt.getMonth() + parseInt(n), 1).getMonthDays(); - if(day > monthDay){ + if (day > monthDay) { day = monthDay; } dt.setDate(day); diff --git a/docs/core.js b/docs/core.js index 3c3a69807..0bd912d24 100644 --- a/docs/core.js +++ b/docs/core.js @@ -23732,7 +23732,6 @@ Date._QN = ["", BI.i18nText("BI-Quarter_1"), BI.i18nText("BI-Quarter_4")]; - /** Adds the number of days array to the Date object. */ Date._MD = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]; @@ -23767,12 +23766,19 @@ Date.prototype.getDayOfYear = function () { /** Returns the number of the week in year, as defined in ISO 8601. */ Date.prototype.getWeekNumber = function () { var d = new Date(this.getFullYear(), this.getMonth(), this.getDate(), 0, 0, 0); - var DoW = d.getDay(); - d.setDate(d.getDate() - (DoW + 6) % 7 + 3); // Nearest Thu + var week = d.getDay(); + if (this.getMonth() === 0 && this.getDate() <= week) { + return 1; + } + d.setDate(this.getDate() - week); var ms = d.valueOf(); // GMT d.setMonth(0); - d.setDate(4); // Thu in Week 1 - return Math.round((ms - d.valueOf()) / (7 * 864e5)) + 1; + d.setDate(1); + var offset = Math.floor((ms - d.valueOf()) / (7 * 864e5)) + 1; + if (d.getDay() > 0) { + offset++; + } + return offset; }; //离当前时间多少天的时间 @@ -23864,7 +23870,7 @@ Date.prototype.getOffsetMonth = function (n) { var dt = new Date(this.getTime()); var day = dt.getDate(); var monthDay = new Date(dt.getFullYear(), dt.getMonth() + parseInt(n), 1).getMonthDays(); - if(day > monthDay){ + if (day > monthDay) { day = monthDay; } dt.setDate(day); diff --git a/src/core/proto/date.js b/src/core/proto/date.js index b25c92d15..36197df93 100644 --- a/src/core/proto/date.js +++ b/src/core/proto/date.js @@ -56,7 +56,6 @@ Date._QN = ["", BI.i18nText("BI-Quarter_1"), BI.i18nText("BI-Quarter_4")]; - /** Adds the number of days array to the Date object. */ Date._MD = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]; @@ -91,12 +90,19 @@ Date.prototype.getDayOfYear = function () { /** Returns the number of the week in year, as defined in ISO 8601. */ Date.prototype.getWeekNumber = function () { var d = new Date(this.getFullYear(), this.getMonth(), this.getDate(), 0, 0, 0); - var DoW = d.getDay(); - d.setDate(d.getDate() - (DoW + 6) % 7 + 3); // Nearest Thu + var week = d.getDay(); + if (this.getMonth() === 0 && this.getDate() <= week) { + return 1; + } + d.setDate(this.getDate() - week); var ms = d.valueOf(); // GMT d.setMonth(0); - d.setDate(4); // Thu in Week 1 - return Math.round((ms - d.valueOf()) / (7 * 864e5)) + 1; + d.setDate(1); + var offset = Math.floor((ms - d.valueOf()) / (7 * 864e5)) + 1; + if (d.getDay() > 0) { + offset++; + } + return offset; }; //离当前时间多少天的时间 @@ -188,7 +194,7 @@ Date.prototype.getOffsetMonth = function (n) { var dt = new Date(this.getTime()); var day = dt.getDate(); var monthDay = new Date(dt.getFullYear(), dt.getMonth() + parseInt(n), 1).getMonthDays(); - if(day > monthDay){ + if (day > monthDay) { day = monthDay; } dt.setDate(day);