12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- import mitt from 'mitt'
- export function dateFormatter (timestamp, type, hideYear = false) {
- const date = new Date(timestamp)
- const year = date.getFullYear()
- const month = date.getMonth() + 1
- const month_0 = (`0${date.getMonth() + 1}`).slice(-2)
- const day = date.getDate()
- const day_0 = (`0${date.getDate()}`).slice(-2)
- const hours = (`0${date.getHours()}`).slice(-2)
- const minutes = (`0${date.getMinutes()}`).slice(-2)
- const seconds = (`0${date.getSeconds()}`).slice(-2)
- const currentYear = new Date().getFullYear()
- const currentMonth = new Date().getMonth() + 1
- const currentDay = new Date().getDate()
-
- const isCurrentDay = year === currentYear && month === currentMonth && day === currentDay
-
- return `${isCurrentDay ? '' : (`${year}-${month_0}-${day_0} `)}${hours}:${minutes}:${seconds}`
- }
- export function _throttle (fn, delay = 1000) {
- let lastTime, timer
- return function () {
- const _this = this
- const args = arguments
- const nowTime = Date.now()
- if (lastTime && nowTime - lastTime < delay) {
- if (timer) clearTimeout(timer)
- timer = setTimeout(() => {
- lastTime = nowTime
- fn.apply(_this, args)
- }, delay)
- } else {
- lastTime = nowTime
- fn.apply(_this, args)
- }
- }
- }
|