|
@@ -1,24 +1,27 @@
|
|
|
class Calendar {
|
|
|
constructor({
|
|
|
+ date,
|
|
|
selected,
|
|
|
startDate,
|
|
|
endDate,
|
|
|
range,
|
|
|
+ // multipleStatus
|
|
|
} = {}) {
|
|
|
// 当前日期
|
|
|
- this.date = this.getDateObj(new Date()) // 当前初入日期
|
|
|
+ this.date = this.getDate(new Date()) // 当前初入日期
|
|
|
// 打点信息
|
|
|
this.selected = selected || [];
|
|
|
- // 起始时间
|
|
|
+ // 范围开始
|
|
|
this.startDate = startDate
|
|
|
- // 终止时间
|
|
|
+ // 范围结束
|
|
|
this.endDate = endDate
|
|
|
- // 是否范围选择
|
|
|
this.range = range
|
|
|
// 多选状态
|
|
|
this.cleanMultipleStatus()
|
|
|
// 每周日期
|
|
|
this.weeks = {}
|
|
|
+ // this._getWeek(this.date.fullDate)
|
|
|
+ // this.multipleStatus = multipleStatus
|
|
|
this.lastHover = false
|
|
|
}
|
|
|
/**
|
|
@@ -26,8 +29,8 @@ class Calendar {
|
|
|
* @param {Object} date
|
|
|
*/
|
|
|
setDate(date) {
|
|
|
- const selectDate = this.getDateObj(date)
|
|
|
- this.getWeeks(selectDate.fullDate)
|
|
|
+ this.selectDate = this.getDate(date)
|
|
|
+ this._getWeek(this.selectDate.fullDate)
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -41,82 +44,93 @@ class Calendar {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- setStartDate(startDate) {
|
|
|
+ /**
|
|
|
+ * 重置开始日期
|
|
|
+ */
|
|
|
+ resetSatrtDate(startDate) {
|
|
|
+ // 范围开始
|
|
|
this.startDate = startDate
|
|
|
+
|
|
|
}
|
|
|
|
|
|
- setEndDate(endDate) {
|
|
|
+ /**
|
|
|
+ * 重置结束日期
|
|
|
+ */
|
|
|
+ resetEndDate(endDate) {
|
|
|
+ // 范围结束
|
|
|
this.endDate = endDate
|
|
|
}
|
|
|
|
|
|
- getPreMonthObj(date){
|
|
|
- date = fixIosDateFormat(date)
|
|
|
- date = new Date(date)
|
|
|
-
|
|
|
- const oldMonth = date.getMonth()
|
|
|
- date.setMonth(oldMonth - 1)
|
|
|
- const newMonth = date.getMonth()
|
|
|
- if(oldMonth !== 0 && newMonth - oldMonth === 0){
|
|
|
- date.setMonth(newMonth - 1)
|
|
|
- }
|
|
|
- return this.getDateObj(date)
|
|
|
- }
|
|
|
- getNextMonthObj(date){
|
|
|
- date = fixIosDateFormat(date)
|
|
|
- date = new Date(date)
|
|
|
-
|
|
|
- const oldMonth = date.getMonth()
|
|
|
- date.setMonth(oldMonth + 1)
|
|
|
- const newMonth = date.getMonth()
|
|
|
- if(newMonth - oldMonth > 1){
|
|
|
- date.setMonth(newMonth - 1)
|
|
|
- }
|
|
|
- return this.getDateObj(date)
|
|
|
- }
|
|
|
-
|
|
|
/**
|
|
|
- * 获取指定格式Date对象
|
|
|
+ * 获取任意时间
|
|
|
*/
|
|
|
- getDateObj(date) {
|
|
|
- date = fixIosDateFormat(date)
|
|
|
- date = new Date(date)
|
|
|
-
|
|
|
+ getDate(date, AddDayCount = 0, str = 'day') {
|
|
|
+ if (!date) {
|
|
|
+ date = new Date()
|
|
|
+ }
|
|
|
+ if (typeof date !== 'object') {
|
|
|
+ date = date.replace(/-/g, '/')
|
|
|
+ }
|
|
|
+ const dd = new Date(date)
|
|
|
+ switch (str) {
|
|
|
+ case 'day':
|
|
|
+ dd.setDate(dd.getDate() + AddDayCount) // 获取AddDayCount天后的日期
|
|
|
+ break
|
|
|
+ case 'month':
|
|
|
+ if (dd.getDate() === 31) {
|
|
|
+ dd.setDate(dd.getDate() + AddDayCount)
|
|
|
+ } else {
|
|
|
+ dd.setMonth(dd.getMonth() + AddDayCount) // 获取AddDayCount天后的日期
|
|
|
+ }
|
|
|
+ break
|
|
|
+ case 'year':
|
|
|
+ dd.setFullYear(dd.getFullYear() + AddDayCount) // 获取AddDayCount天后的日期
|
|
|
+ break
|
|
|
+ }
|
|
|
+ const y = dd.getFullYear()
|
|
|
+ const m = dd.getMonth() + 1 < 10 ? '0' + (dd.getMonth() + 1) : dd.getMonth() + 1 // 获取当前月份的日期,不足10补0
|
|
|
+ const d = dd.getDate() < 10 ? '0' + dd.getDate() : dd.getDate() // 获取当前几号,不足10补0
|
|
|
return {
|
|
|
- fullDate: getDate(date),
|
|
|
- year: date.getFullYear(),
|
|
|
- month: addZero(date.getMonth() + 1),
|
|
|
- date: addZero(date.getDate()),
|
|
|
- day: date.getDay()
|
|
|
+ fullDate: y + '-' + m + '-' + d,
|
|
|
+ year: y,
|
|
|
+ month: m,
|
|
|
+ date: d,
|
|
|
+ day: dd.getDay()
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+
|
|
|
/**
|
|
|
- * 获取上一个月日期集合
|
|
|
+ * 获取上月剩余天数
|
|
|
*/
|
|
|
- getPreMonthDays(amount, dateObj) {
|
|
|
- const result = []
|
|
|
- for (let i = amount - 1; i >= 0; i--) {
|
|
|
- const month = dateObj.month - 1
|
|
|
- result.push({
|
|
|
- date: new Date(dateObj.year, month, -i).getDate(),
|
|
|
- month,
|
|
|
+ _getLastMonthDays(firstDay, full) {
|
|
|
+ let dateArr = []
|
|
|
+ for (let i = firstDay; i > 0; i--) {
|
|
|
+ const beforeDate = new Date(full.year, full.month - 1, -i + 1).getDate()
|
|
|
+ dateArr.push({
|
|
|
+ date: beforeDate,
|
|
|
+ month: full.month - 1,
|
|
|
disable: true
|
|
|
})
|
|
|
}
|
|
|
- return result
|
|
|
+ return dateArr
|
|
|
}
|
|
|
/**
|
|
|
- * 获取本月日期集合
|
|
|
+ * 获取本月天数
|
|
|
*/
|
|
|
- getCurrentMonthDays(amount, dateObj) {
|
|
|
- const result = []
|
|
|
- const fullDate = this.date.fullDate
|
|
|
- for (let i = 1; i <= amount; i++) {
|
|
|
- const currentDate = `${dateObj.year}-${dateObj.month}-${addZero(i)}`
|
|
|
- const isToday = fullDate === currentDate
|
|
|
+ _currentMonthDys(dateData, full) {
|
|
|
+ let dateArr = []
|
|
|
+ let fullDate = this.date.fullDate
|
|
|
+ for (let i = 1; i <= dateData; i++) {
|
|
|
+ let isinfo = false
|
|
|
+ let nowDate = full.year + '-' + (full.month < 10 ?
|
|
|
+ full.month : full.month) + '-' + (i < 10 ?
|
|
|
+ '0' + i : i)
|
|
|
+ // 是否今天
|
|
|
+ let isDay = fullDate === nowDate
|
|
|
// 获取打点信息
|
|
|
- const info = this.selected && this.selected.find((item) => {
|
|
|
- if (this.dateEqual(currentDate, item.date)) {
|
|
|
+ let info = this.selected && this.selected.find((item) => {
|
|
|
+ if (this.dateEqual(nowDate, item.date)) {
|
|
|
return item
|
|
|
}
|
|
|
})
|
|
@@ -125,52 +139,62 @@ class Calendar {
|
|
|
let disableBefore = true
|
|
|
let disableAfter = true
|
|
|
if (this.startDate) {
|
|
|
- disableBefore = dateCompare(this.startDate, currentDate)
|
|
|
+ // let dateCompBefore = this.dateCompare(this.startDate, fullDate)
|
|
|
+ // disableBefore = this.dateCompare(dateCompBefore ? this.startDate : fullDate, nowDate)
|
|
|
+ disableBefore = this.dateCompare(this.startDate, nowDate)
|
|
|
}
|
|
|
|
|
|
if (this.endDate) {
|
|
|
- disableAfter = dateCompare(currentDate, this.endDate)
|
|
|
+ // let dateCompAfter = this.dateCompare(fullDate, this.endDate)
|
|
|
+ // disableAfter = this.dateCompare(nowDate, dateCompAfter ? this.endDate : fullDate)
|
|
|
+ disableAfter = this.dateCompare(nowDate, this.endDate)
|
|
|
}
|
|
|
-
|
|
|
let multiples = this.multipleStatus.data
|
|
|
+ let checked = false
|
|
|
let multiplesStatus = -1
|
|
|
- if (this.range && multiples) {
|
|
|
- multiplesStatus = multiples.findIndex((item) => {
|
|
|
- return this.dateEqual(item, currentDate)
|
|
|
- })
|
|
|
+ if (this.range) {
|
|
|
+ if (multiples) {
|
|
|
+ multiplesStatus = multiples.findIndex((item) => {
|
|
|
+ return this.dateEqual(item, nowDate)
|
|
|
+ })
|
|
|
+ }
|
|
|
+ if (multiplesStatus !== -1) {
|
|
|
+ checked = true
|
|
|
+ }
|
|
|
}
|
|
|
- const checked = multiplesStatus !== -1
|
|
|
-
|
|
|
- result.push({
|
|
|
- fullDate: currentDate,
|
|
|
- year: dateObj.year,
|
|
|
+ let data = {
|
|
|
+ fullDate: nowDate,
|
|
|
+ year: full.year,
|
|
|
date: i,
|
|
|
multiple: this.range ? checked : false,
|
|
|
- beforeMultiple: this.isLogicBefore(currentDate, this.multipleStatus.before, this.multipleStatus.after),
|
|
|
- afterMultiple: this.isLogicAfter(currentDate, this.multipleStatus.before, this.multipleStatus.after),
|
|
|
- month: dateObj.month,
|
|
|
- disable: (this.startDate && !dateCompare(this.startDate, currentDate)) || (this.endDate && !dateCompare(currentDate,this.endDate)),
|
|
|
- isToday,
|
|
|
- userChecked: false,
|
|
|
- extraInfo: info
|
|
|
- })
|
|
|
+ beforeMultiple: this.isLogicBefore(nowDate, this.multipleStatus.before, this.multipleStatus.after),
|
|
|
+ afterMultiple: this.isLogicAfter(nowDate, this.multipleStatus.before, this.multipleStatus.after),
|
|
|
+ month: full.month,
|
|
|
+ disable: !(disableBefore && disableAfter),
|
|
|
+ isDay,
|
|
|
+ userChecked: false
|
|
|
+ }
|
|
|
+ if (info) {
|
|
|
+ data.extraInfo = info
|
|
|
+ }
|
|
|
+
|
|
|
+ dateArr.push(data)
|
|
|
}
|
|
|
- return result
|
|
|
+ return dateArr
|
|
|
}
|
|
|
/**
|
|
|
- * 获取下一个月日期集合
|
|
|
+ * 获取下月天数
|
|
|
*/
|
|
|
- _getNextMonthDays(amount, dateObj) {
|
|
|
- const result = []
|
|
|
- const month = dateObj.month + 1
|
|
|
- for (let i = 1; i <= amount; i++) {
|
|
|
- result.push({
|
|
|
+ _getNextMonthDays(surplus, full) {
|
|
|
+ let dateArr = []
|
|
|
+ for (let i = 1; i < surplus + 1; i++) {
|
|
|
+ dateArr.push({
|
|
|
date: i,
|
|
|
- month,
|
|
|
+ month: Number(full.month) + 1,
|
|
|
disable: true
|
|
|
})
|
|
|
}
|
|
|
- return result
|
|
|
+ return dateArr
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -181,37 +205,58 @@ class Calendar {
|
|
|
if (!date) {
|
|
|
date = new Date()
|
|
|
}
|
|
|
+ const dateInfo = this.canlender.find(item => item.fullDate === this.getDate(date).fullDate)
|
|
|
+ return dateInfo
|
|
|
+ }
|
|
|
|
|
|
- return this.calendar.find(item => item.fullDate === this.getDateObj(date).fullDate)
|
|
|
+ /**
|
|
|
+ * 比较时间大小
|
|
|
+ */
|
|
|
+ dateCompare(startDate, endDate) {
|
|
|
+ // 计算截止时间
|
|
|
+ startDate = new Date(startDate.replace('-', '/').replace('-', '/'))
|
|
|
+ // 计算详细项的截止时间
|
|
|
+ endDate = new Date(endDate.replace('-', '/').replace('-', '/'))
|
|
|
+ if (startDate <= endDate) {
|
|
|
+ return true
|
|
|
+ } else {
|
|
|
+ return false
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 比较时间是否相等
|
|
|
*/
|
|
|
dateEqual(before, after) {
|
|
|
- before = new Date(fixIosDateFormat(before))
|
|
|
- after = new Date(fixIosDateFormat(after))
|
|
|
- return before.valueOf() === after.valueOf()
|
|
|
+ // 计算截止时间
|
|
|
+ before = new Date(before.replace('-', '/').replace('-', '/'))
|
|
|
+ // 计算详细项的截止时间
|
|
|
+ after = new Date(after.replace('-', '/').replace('-', '/'))
|
|
|
+ if (before.getTime() - after.getTime() === 0) {
|
|
|
+ return true
|
|
|
+ } else {
|
|
|
+ return false
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 比较真实起始日期
|
|
|
*/
|
|
|
|
|
|
- isLogicBefore(currentDate, before, after) {
|
|
|
+ isLogicBefore(currentDay, before, after) {
|
|
|
let logicBefore = before
|
|
|
if (before && after) {
|
|
|
- logicBefore = dateCompare(before, after) ? before : after
|
|
|
+ logicBefore = this.dateCompare(before, after) ? before : after
|
|
|
}
|
|
|
- return this.dateEqual(logicBefore, currentDate)
|
|
|
+ return this.dateEqual(logicBefore, currentDay)
|
|
|
}
|
|
|
|
|
|
- isLogicAfter(currentDate, before, after) {
|
|
|
+ isLogicAfter(currentDay, before, after) {
|
|
|
let logicAfter = after
|
|
|
if (before && after) {
|
|
|
- logicAfter = dateCompare(before, after) ? after : before
|
|
|
+ logicAfter = this.dateCompare(before, after) ? after : before
|
|
|
}
|
|
|
- return this.dateEqual(logicAfter, currentDate)
|
|
|
+ return this.dateEqual(logicAfter, currentDay)
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -231,7 +276,7 @@ class Calendar {
|
|
|
var unixDe = de.getTime() - 24 * 60 * 60 * 1000
|
|
|
for (var k = unixDb; k <= unixDe;) {
|
|
|
k = k + 24 * 60 * 60 * 1000
|
|
|
- arr.push(this.getDateObj(new Date(parseInt(k))).fullDate)
|
|
|
+ arr.push(this.getDate(new Date(parseInt(k))).fullDate)
|
|
|
}
|
|
|
return arr
|
|
|
}
|
|
@@ -240,12 +285,11 @@ class Calendar {
|
|
|
* 获取多选状态
|
|
|
*/
|
|
|
setMultiple(fullDate) {
|
|
|
- if (!this.range) return
|
|
|
-
|
|
|
let {
|
|
|
before,
|
|
|
after
|
|
|
} = this.multipleStatus
|
|
|
+ if (!this.range) return
|
|
|
if (before && after) {
|
|
|
if (!this.lastHover) {
|
|
|
this.lastHover = true
|
|
@@ -262,7 +306,7 @@ class Calendar {
|
|
|
this.lastHover = false
|
|
|
} else {
|
|
|
this.multipleStatus.after = fullDate
|
|
|
- if (dateCompare(this.multipleStatus.before, this.multipleStatus.after)) {
|
|
|
+ if (this.dateCompare(this.multipleStatus.before, this.multipleStatus.after)) {
|
|
|
this.multipleStatus.data = this.geDateAll(this.multipleStatus.before, this.multipleStatus
|
|
|
.after);
|
|
|
} else {
|
|
@@ -272,28 +316,32 @@ class Calendar {
|
|
|
this.lastHover = true
|
|
|
}
|
|
|
}
|
|
|
- this.getWeeks(fullDate)
|
|
|
+ this._getWeek(fullDate)
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 鼠标 hover 更新多选状态
|
|
|
*/
|
|
|
setHoverMultiple(fullDate) {
|
|
|
- if (!this.range || this.lastHover) return
|
|
|
+ let {
|
|
|
+ before,
|
|
|
+ after
|
|
|
+ } = this.multipleStatus
|
|
|
|
|
|
- const { before } = this.multipleStatus
|
|
|
+ if (!this.range) return
|
|
|
+ if (this.lastHover) return
|
|
|
|
|
|
if (!before) {
|
|
|
this.multipleStatus.before = fullDate
|
|
|
} else {
|
|
|
this.multipleStatus.after = fullDate
|
|
|
- if (dateCompare(this.multipleStatus.before, this.multipleStatus.after)) {
|
|
|
+ if (this.dateCompare(this.multipleStatus.before, this.multipleStatus.after)) {
|
|
|
this.multipleStatus.data = this.geDateAll(this.multipleStatus.before, this.multipleStatus.after);
|
|
|
} else {
|
|
|
this.multipleStatus.data = this.geDateAll(this.multipleStatus.after, this.multipleStatus.before);
|
|
|
}
|
|
|
}
|
|
|
- this.getWeeks(fullDate)
|
|
|
+ this._getWeek(fullDate)
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -303,12 +351,12 @@ class Calendar {
|
|
|
this.multipleStatus.before = before
|
|
|
this.multipleStatus.after = after
|
|
|
if (before && after) {
|
|
|
- if (dateCompare(before, after)) {
|
|
|
+ if (this.dateCompare(before, after)) {
|
|
|
this.multipleStatus.data = this.geDateAll(before, after);
|
|
|
- this.getWeeks(after)
|
|
|
+ this._getWeek(after)
|
|
|
} else {
|
|
|
this.multipleStatus.data = this.geDateAll(after, before);
|
|
|
- this.getWeeks(before)
|
|
|
+ this._getWeek(before)
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -317,87 +365,46 @@ class Calendar {
|
|
|
* 获取每周数据
|
|
|
* @param {Object} dateData
|
|
|
*/
|
|
|
- getWeeks(dateData) {
|
|
|
+ _getWeek(dateData) {
|
|
|
const {
|
|
|
+ fullDate,
|
|
|
year,
|
|
|
month,
|
|
|
- } = this.getDateObj(dateData)
|
|
|
-
|
|
|
- const preMonthDayAmount = new Date(year, month - 1, 1).getDay()
|
|
|
- const preMonthDays = this.getPreMonthDays(preMonthDayAmount, this.getDateObj(dateData))
|
|
|
-
|
|
|
- const currentMonthDayAmount = new Date(year, month, 0).getDate()
|
|
|
- const currentMonthDays = this.getCurrentMonthDays(currentMonthDayAmount, this.getDateObj(dateData))
|
|
|
-
|
|
|
- const nextMonthDayAmount = 42 - preMonthDayAmount - currentMonthDayAmount
|
|
|
- const nextMonthDays = this._getNextMonthDays(nextMonthDayAmount, this.getDateObj(dateData))
|
|
|
-
|
|
|
- const calendarDays = [...preMonthDays, ...currentMonthDays, ...nextMonthDays]
|
|
|
-
|
|
|
- const weeks = new Array(6)
|
|
|
- for (let i = 0; i < calendarDays.length; i++) {
|
|
|
- const index = Math.floor(i / 7)
|
|
|
- if(!weeks[index]){
|
|
|
- weeks[index] = new Array(7)
|
|
|
- }
|
|
|
- weeks[index][i % 7] = calendarDays[i]
|
|
|
+ date,
|
|
|
+ day
|
|
|
+ } = this.getDate(dateData)
|
|
|
+ let firstDay = new Date(year, month - 1, 1).getDay()
|
|
|
+ let currentDay = new Date(year, month, 0).getDate()
|
|
|
+ let dates = {
|
|
|
+ lastMonthDays: this._getLastMonthDays(firstDay, this.getDate(dateData)), // 上个月末尾几天
|
|
|
+ currentMonthDys: this._currentMonthDys(currentDay, this.getDate(dateData)), // 本月天数
|
|
|
+ nextMonthDays: [], // 下个月开始几天
|
|
|
+ weeks: []
|
|
|
}
|
|
|
-
|
|
|
- this.calendar = calendarDays
|
|
|
+ let canlender = []
|
|
|
+ const surplus = 42 - (dates.lastMonthDays.length + dates.currentMonthDys.length)
|
|
|
+ dates.nextMonthDays = this._getNextMonthDays(surplus, this.getDate(dateData))
|
|
|
+ canlender = canlender.concat(dates.lastMonthDays, dates.currentMonthDys, dates.nextMonthDays)
|
|
|
+ let weeks = {}
|
|
|
+ // 拼接数组 上个月开始几天 + 本月天数+ 下个月开始几天
|
|
|
+ for (let i = 0; i < canlender.length; i++) {
|
|
|
+ if (i % 7 === 0) {
|
|
|
+ weeks[parseInt(i / 7)] = new Array(7)
|
|
|
+ }
|
|
|
+ weeks[parseInt(i / 7)][i % 7] = canlender[i]
|
|
|
+ }
|
|
|
+ this.canlender = canlender
|
|
|
this.weeks = weeks
|
|
|
}
|
|
|
-}
|
|
|
-
|
|
|
-function getDateTime(date, hideSecond){
|
|
|
- return `${getDate(date)} ${getTime(date, hideSecond)}`
|
|
|
-}
|
|
|
-
|
|
|
-function getDate(date) {
|
|
|
- date = fixIosDateFormat(date)
|
|
|
- date = new Date(date)
|
|
|
- const year = date.getFullYear()
|
|
|
- const month = date.getMonth()+1
|
|
|
- const day = date.getDate()
|
|
|
- return `${year}-${addZero(month)}-${addZero(day)}`
|
|
|
-}
|
|
|
-
|
|
|
-function getTime(date, hideSecond){
|
|
|
- date = fixIosDateFormat(date)
|
|
|
- date = new Date(date)
|
|
|
- const hour = date.getHours()
|
|
|
- const minute = date.getMinutes()
|
|
|
- const second = date.getSeconds()
|
|
|
- return hideSecond ? `${addZero(hour)}:${addZero(minute)}` : `${addZero(hour)}:${addZero(minute)}:${addZero(second)}`
|
|
|
-}
|
|
|
|
|
|
-function addZero(num) {
|
|
|
- if(num < 10){
|
|
|
- num = `0${num}`
|
|
|
- }
|
|
|
- return num
|
|
|
+ //静态方法
|
|
|
+ // static init(date) {
|
|
|
+ // if (!this.instance) {
|
|
|
+ // this.instance = new Calendar(date);
|
|
|
+ // }
|
|
|
+ // return this.instance;
|
|
|
+ // }
|
|
|
}
|
|
|
|
|
|
-function getDefaultSecond(hideSecond) {
|
|
|
- return hideSecond ? '00:00' : '00:00:00'
|
|
|
-}
|
|
|
-
|
|
|
-function dateCompare(startDate, endDate) {
|
|
|
- startDate = new Date(fixIosDateFormat(startDate))
|
|
|
- endDate = new Date(fixIosDateFormat(endDate))
|
|
|
- return startDate <= endDate
|
|
|
-}
|
|
|
-
|
|
|
-function checkDate(date){
|
|
|
- const dateReg = /((19|20)\d{2})(-|\/)\d{1,2}(-|\/)\d{1,2}/g
|
|
|
- return date.match(dateReg)
|
|
|
-}
|
|
|
-
|
|
|
-const dateTimeReg = /^\d{4}-(0[1-9]|1[012])-(0[1-9]|[12][0-9]|3[01])( [0-5][0-9]:[0-5][0-9]:[0-5][0-9])?$/
|
|
|
-function fixIosDateFormat(value) {
|
|
|
- if (typeof value === 'string' && dateTimeReg.test(value)) {
|
|
|
- value = value.replace(/-/g, '/')
|
|
|
- }
|
|
|
- return value
|
|
|
-}
|
|
|
|
|
|
-export {Calendar, getDateTime, getDate, getTime, addZero, getDefaultSecond, dateCompare, checkDate, fixIosDateFormat}
|
|
|
+export default Calendar
|