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

View File

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