test: utils/date

This commit is contained in:
DIYgod
2019-01-22 18:01:23 +08:00
parent a3f70f8e37
commit d00c4dc263
5 changed files with 76 additions and 4 deletions

View File

@@ -1,5 +1,7 @@
// 格式化 类型这个的时间 几分钟前 | 几小时前 | 几天前 | 几月前 | 几年前 | 具体的格式不对的时间
module.exports = (html, timeZone) => {
const serverOffset = new Date().getTimezoneOffset() / 60;
module.exports = (html, timeZone = -serverOffset) => {
let math;
let date = new Date();
if (/(\d+)分钟前/.exec(html)) {
@@ -46,8 +48,7 @@ module.exports = (html, timeZone) => {
date = new Date(date.getFullYear(), date.getMonth(), date.getDate(), math[1], math[2]);
}
if (date && timeZone) {
const serverOffset = new Date().getTimezoneOffset() / 60;
if (date) {
return new Date(date.getTime() - 60 * 60 * 1000 * (timeZone + serverOffset)).toUTCString();
}
return html;