feat(ganttDb.js): add 1 day to end dates if inclusive is set to true

This will essentially keep all old behavior the same while still allowing users to specify if they want inclusive end dates
This commit is contained in:
Jason Würtz 2019-07-06 12:27:28 -03:00
parent b5b714861d
commit 63096a5c26
1 changed files with 9 additions and 2 deletions

View File

@ -11,6 +11,7 @@ let tasks = []
let currentSection = ''
const tags = ['active', 'done', 'crit', 'milestone']
let funs = []
let inclusiveEndDates = false
export const clear = function () {
sections = []
@ -25,6 +26,7 @@ export const clear = function () {
dateFormat = ''
axisFormat = ''
excludes = []
inclusiveEndDates = false
}
export const setAxisFormat = function (txt) {
@ -35,8 +37,9 @@ export const getAxisFormat = function () {
return axisFormat
}
export const setDateFormat = function (txt) {
export const setDateFormat = function (txt, inclusive) {
dateFormat = txt
inclusiveEndDates = inclusive || false // make sure it's not undefined
}
export const getDateFormat = function () {
@ -149,12 +152,16 @@ const getStartDate = function (prevTime, dateFormat, str) {
return new Date()
}
const getEndDate = function (prevTime, dateFormat, str) {
const getEndDate = function (prevTime, dateFormat, str, inclusive) {
inclusive = inclusive || false
str = str.trim()
// Check for actual date
let mDate = moment(str, dateFormat.trim(), true)
if (mDate.isValid()) {
if (inclusive) {
mDate.add(1, 'd')
}
return mDate.toDate()
}