diff --git a/flowable-engine-web/src/utils/date.js b/flowable-engine-web/src/utils/date.js index 43be1e3..5af3ebb 100644 --- a/flowable-engine-web/src/utils/date.js +++ b/flowable-engine-web/src/utils/date.js @@ -1,4 +1,6 @@ //时间转换为String类型 +const moment = require("moment"); + function simpleDateFormat(pattern) { var fmt = new Object(); fmt.pattern = pattern; @@ -62,9 +64,9 @@ function simpleDateFormatByMoreLine(date) { /** * @param dateBegin 开始时间 * @param dateEnd 结束时间 - * @returns {string} 时间差 + * @returns {string} 时间差 天 小时 分钟 秒 */ -function consumingTime(dateBegin,dateEnd) { +function consumingTime(dateBegin, dateEnd) { // //如果时间格式是正确的,那下面这一步转化时间格式就可以不用了 let submitTime = new Date(dateBegin) let endTime = new Date(dateEnd) @@ -81,7 +83,36 @@ function consumingTime(dateBegin,dateEnd) { return dayDiff + "天 " + hours + "小时 " + minutes + " 分钟" + seconds + " 秒"; } +function timeLength(start, dateEnd) { + // //如果时间格式是正确的,那下面这一步转化时间格式就可以不用了 + let mstart = moment(start); + let mend = moment(dateEnd); + let years = mend.diff(start, "years"); + let months = mend.diff(start, "months"); + let days = mend.diff(start, "days"); + let hours = mend.diff(start, "hours"); + let minutes = mend.diff(start, "minutes"); + minutes = minutes % 60; + hours = hours % 24; + months = months % 12; + //因为每月天不固定,所以天要特殊动态处理 + if (mstart.date() < mend.date()) { + days = mend.date() - mstart.date(); + if (minutes > 0 || hours > 0) { + days--; + } + } + //处理超过俩月且天超过31 + if (days > 31 && mend.month() - mstart.month() >= 2) { + //将日期推至上月求差 + days = mend.diff(mstart.add(mend.month() - mstart.month() - 1, "month"), "days"); + } + return `${years > 0 ? years + "年 " : " "}` + `${months > 0 ? months + "个月 " : " "}` + `${days > 0 ? days + "天 " : " "}` + + `${hours > 0 ? hours + "小时 " : " "}` + `${minutes > 0 ? minutes + "分钟 " : " "}`; +} + module.exports = { formatToYYYYMMDD: simpleDateFormatByMoreLine, - consumingTime: consumingTime + consumingTime: consumingTime, + timeLength: timeLength } diff --git a/flowable-engine-web/src/views/common/form/components/DateTimeRange.vue b/flowable-engine-web/src/views/common/form/components/DateTimeRange.vue index e9d4b40..2250c62 100644 --- a/flowable-engine-web/src/views/common/form/components/DateTimeRange.vue +++ b/flowable-engine-web/src/views/common/form/components/DateTimeRange.vue @@ -37,6 +37,7 @@