Skip to content

Commit 1952483

Browse files
committed
initial attempt to use Lib.incrementMonth to compute endDate
1 parent 8d9411b commit 1952483

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

src/plots/cartesian/align_period.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ var isNumeric = require('fast-isnumeric');
1212
var Lib = require('../../lib');
1313
var ms2DateTime = Lib.ms2DateTime;
1414
var dateTime2ms = Lib.dateTime2ms;
15+
var incrementMonth = Lib.incrementMonth;
1516
var constants = require('../../constants/numerical');
1617
var ONEDAY = constants.ONEDAY;
1718
var ONEAVGMONTH = constants.ONEAVGMONTH;
@@ -24,13 +25,16 @@ module.exports = function alignPeriod(trace, ax, axLetter, vals) {
2425
if(!alignment) return vals;
2526

2627
var period = trace[axLetter + 'period'];
28+
var mPeriod;
2729
if(isNumeric(period)) {
2830
period = +period;
2931
if(period <= 0) return vals;
3032
} else if(typeof period === 'string' && period.charAt(0) === 'M') {
3133
var n = +(period.substring(1));
32-
if(n > 0 && Math.round(n) === n) period = n * ONEAVGMONTH;
33-
else return vals;
34+
if(n > 0 && Math.round(n) === n) {
35+
mPeriod = n;
36+
period = n * ONEAVGMONTH;
37+
} else return vals;
3438
}
3539

3640
if(period > 0) {
@@ -82,11 +86,7 @@ module.exports = function alignPeriod(trace, ax, axLetter, vals) {
8286
endTime = (new Date(y1, m1, d1)).getTime();
8387
} else if(nMonths) {
8488
startTime = (new Date(year, nYears ? month : roundMonth(month, nMonths))).getTime();
85-
if(m1 > 11) {
86-
m1 -= 12;
87-
y1 += 1;
88-
}
89-
endTime = (new Date(y1, nYears ? m1 : roundMonth(m1, nMonths))).getTime();
89+
endTime = incrementMonth(startTime, mPeriod ? mPeriod : nMonths, calendar);
9090
} else {
9191
startTime = (new Date(year, 0)).getTime();
9292
endTime = (new Date(y1, 0)).getTime();

0 commit comments

Comments
 (0)