Skip to content

Commit 46ec3f4

Browse files
committed
calculate years from months - add 2020 Mondays test
1 parent 14c5512 commit 46ec3f4

File tree

4 files changed

+405
-3
lines changed

4 files changed

+405
-3
lines changed

src/plots/cartesian/align_period.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,9 @@ module.exports = function alignPeriod(trace, ax, axLetter, vals) {
5656
var startTime;
5757
var endTime;
5858

59-
var nYears = Math.floor(period / ONEAVGYEAR);
6059
var nMonths = Math.floor(period / ONEAVGMONTH) % 12;
61-
var nDays = Math.floor((period - nYears * ONEAVGYEAR - nMonths * ONEAVGMONTH) / ONEDAY);
60+
var nYears = Math.floor((period - nMonths * ONEAVGMONTH) / ONEAVGYEAR);
61+
var nDays = Math.floor((period - nMonths * ONEAVGMONTH - nYears * ONEAVGYEAR) / ONEDAY);
6262
if(nYears && nMonths) nDays = 0;
6363

6464
var y1 = year + nYears;
@@ -67,7 +67,7 @@ module.exports = function alignPeriod(trace, ax, axLetter, vals) {
6767
if(nDays || nMonths || nYears) {
6868
if(nDays) {
6969
startTime = (new Date(year, month, day)).getTime();
70-
var monthDays = new Date(y1, m1, 0).getDate();
70+
var monthDays = new Date(y1, m1 + 1, 0).getDate();
7171
if(d1 > monthDays) {
7272
d1 -= monthDays;
7373
m1 += 1;
58.4 KB
Loading

0 commit comments

Comments
 (0)