'How to fix "getMonth" showing next year's month too
my problem is that the months are displaying till "April" which means starting from Jan to Next Year's April. I only need to display months till December.
This is my JavaScript code
var vals = [date.getFullYear() + (scale === YEAR ? qty : 0),
date.getMonth() + (scale === MONTH ? qty : 0),
date.getDate() + (scale === DAY ? qty : 0),
date.getHours() + (scale === HOUR ? qty : 0),
date.getMinutes() + (scale === MINUTE ? qty : 0),
date.getSeconds() + (scale === SECOND ? qty : 0),
date.getMilliseconds() + (scale === MILLISECOND ? qty : 0)
];
return new Date(...vals);
},
start_of(date, scale) {
const scores = {
[YEAR]: 6,
[MONTH]: 5,
[DAY]: 4,
[HOUR]: 3,
[MINUTE]: 2,
[SECOND]: 1,
[MILLISECOND]: 0
};
function should_reset(_scale) {
const max_score = scores[scale];
return scores[_scale] <= max_score;
}
const vals = [
date.getFullYear(),
should_reset(YEAR) ? 0 : date.getMonth(),
should_reset(MONTH) ? 1 : date.getDate(),
should_reset(DAY) ? 0 : date.getHours(),
should_reset(HOUR) ? 0 : date.getMinutes(),
should_reset(MINUTE) ? 0 : date.getSeconds(),
should_reset(SECOND) ? 0 : date.getMilliseconds()
];
return new Date(...vals);
},
<script>
document.addEventListener('DOMContentLoaded', function() {
var gantt_data = <?php echo json_encode($gantt_data); ?>;
if (gantt_data.length > 0) {
var gantt = new Gantt("#gantt", gantt_data, {
view_modes: ['Day', 'Week', 'Month', 'Year'],
view_mode: 'Month',
date_format: 'YYYY-MM-DD',
column_width: 30,
});
$("#gantt g.handle-group").hide();
$('body').on('mouseleave', '.grid-row', function() {
gantt.hide_popup();
})
$('select[name$="gantt_view"').change(function(el) {
let view = $(el.target).val();
gantt.change_view_mode(view);
});
}
})
</script>
I am not sure if something else could be causing this problem. I'm using Gantt chart and I only want to display 12 months.
I'm using this gantt. https://github.com/frappe/gantt
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|