Commit 28295360a8dddfaba5ee69ec53e8b016882738ce
1 parent
6918b81d
update Time logic
Showing
2 changed files
with
6 additions
and
8 deletions
Show diff stats
examples/routers/time.vue
src/components/time/time.js
| ... | ... | @@ -3,9 +3,9 @@ |
| 3 | 3 | * @returns {Boolean} |
| 4 | 4 | */ |
| 5 | 5 | // const isMillisecond = timeStamp => { |
| 6 | -// const timeStr = String(timeStamp); | |
| 7 | -// return timeStr.length > 10; | |
| 8 | -// }; | |
| 6 | +// const timeStr = String(timeStamp) | |
| 7 | +// return timeStr.length > 10 | |
| 8 | +// } | |
| 9 | 9 | |
| 10 | 10 | /** |
| 11 | 11 | * @param {Number} timeStamp 传入的时间戳 |
| ... | ... | @@ -49,7 +49,6 @@ const getDate = (timeStamp, startType) => { |
| 49 | 49 | */ |
| 50 | 50 | export const getRelativeTime = timeStamp => { |
| 51 | 51 | // 判断当前传入的时间戳是秒格式还是毫秒 |
| 52 | - // const IS_MILLISECOND = isMillisecond(timeStamp); | |
| 53 | 52 | const IS_MILLISECOND = true; |
| 54 | 53 | // 如果是毫秒格式则转为秒格式 |
| 55 | 54 | if (IS_MILLISECOND) Math.floor(timeStamp /= 1000); |
| ... | ... | @@ -73,9 +72,8 @@ export const getRelativeTime = timeStamp => { |
| 73 | 72 | else if (diff > 3599 && diff <= 86399) resStr = Math.floor(diff / 3600) + '小时' + dirStr; |
| 74 | 73 | // 多于23小时59分钟59秒,少于等于29天59分钟59秒 |
| 75 | 74 | else if (diff > 86399 && diff <= 2623859) resStr = Math.floor(diff / 86400) + '天' + dirStr; |
| 76 | - // 多于29天59分钟59秒,少于364天23小时59分钟59秒 | |
| 77 | - else if (diff > 2623859 && diff <= 31567859) resStr = getDate(timeStamp); | |
| 78 | - // 多于364天23小时59分钟59秒 | |
| 75 | + // 多于29天59分钟59秒,少于364天23小时59分钟59秒,且传入的时间戳早于当前 | |
| 76 | + else if (diff > 2623859 && diff <= 31567859 && IS_EARLY) resStr = getDate(timeStamp); | |
| 79 | 77 | else resStr = getDate(timeStamp, 'year'); |
| 80 | 78 | return resStr; |
| 81 | 79 | }; | ... | ... |