diff --git a/bi/core.js b/bi/core.js index d9254f202..d36ff77a3 100644 --- a/bi/core.js +++ b/bi/core.js @@ -6354,6 +6354,20 @@ Date.prototype.getQuarterStartMonth = function () { } return quarterStartMonth; }; + +//指定日期n个月之前或之后的日期 +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){ + day = monthDay; + } + dt.setDate(day); + dt.setMonth(dt.getMonth() + parseInt(n)); + return dt; +}; + //获得本季度的起始日期 Date.prototype.getQuarterStartDate = function () { return new Date(this.getFullYear(), this.getQuarterStartMonth(), 1); diff --git a/docs/core.js b/docs/core.js index ca61c1ec3..dcd1f9474 100644 --- a/docs/core.js +++ b/docs/core.js @@ -23834,6 +23834,20 @@ Date.prototype.getQuarterStartMonth = function () { } return quarterStartMonth; }; + +//指定日期n个月之前或之后的日期 +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){ + day = monthDay; + } + dt.setDate(day); + dt.setMonth(dt.getMonth() + parseInt(n)); + return dt; +}; + //获得本季度的起始日期 Date.prototype.getQuarterStartDate = function () { return new Date(this.getFullYear(), this.getQuarterStartMonth(), 1); diff --git a/src/core/proto/date.js b/src/core/proto/date.js index 1ae8b5959..e3146708b 100644 --- a/src/core/proto/date.js +++ b/src/core/proto/date.js @@ -182,6 +182,20 @@ Date.prototype.getQuarterStartMonth = function () { } return quarterStartMonth; }; + +//指定日期n个月之前或之后的日期 +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){ + day = monthDay; + } + dt.setDate(day); + dt.setMonth(dt.getMonth() + parseInt(n)); + return dt; +}; + //获得本季度的起始日期 Date.prototype.getQuarterStartDate = function () { return new Date(this.getFullYear(), this.getQuarterStartMonth(), 1);