From ef80b937fe5aa50a0afe49d8cf8f1c13a8bae5c5 Mon Sep 17 00:00:00 2001 From: Cloud Date: Mon, 8 Jul 2019 21:59:26 +0800 Subject: [PATCH] feat: replace luxon to native Date (#2586) --- lib/routes/bangumi/subject/comments.js | 11 +++-------- lib/routes/bangumi/subject/offcial-subject-api.js | 3 +-- package.json | 1 - yarn.lock | 5 ----- 4 files changed, 4 insertions(+), 16 deletions(-) diff --git a/lib/routes/bangumi/subject/comments.js b/lib/routes/bangumi/subject/comments.js index 60f030047..777d1cc68 100644 --- a/lib/routes/bangumi/subject/comments.js +++ b/lib/routes/bangumi/subject/comments.js @@ -1,6 +1,5 @@ const got = require('@/utils/got'); const cheerio = require('cheerio'); -const DateTime = require('luxon').DateTime; module.exports = async (subjectID, minLength) => { // bangumi.tv未提供获取“吐槽(comments)”的API,因此仍需要通过抓取网页来获取 @@ -31,21 +30,17 @@ module.exports = async (subjectID, minLength) => { .slice(1) .map((s) => (s ? Number(s.slice(0, -2)) : 0)); - date = DateTime.local().minus({ - days: list[0], - hours: list[1], - minutes: list[2], - }); + date = new Date(new Date().getTime() - 1000 * 60 * 60 * 24 * list[0] - 1000 * 60 * 60 * list[1] - 1000 * 60 * list[2]).toUTCString(); } else { // 表示绝对日期的字符串 - date = DateTime.fromFormat(dateString, 'yyyy-L-dd HH:mm'); + date = new Date(dateString).toUTCString(); } return { user: $el.find('.l').text(), rate: rate || '无', content: $el.find('p').text(), - date: date.toRFC2822(), + date: date, }; }) .get() diff --git a/lib/routes/bangumi/subject/offcial-subject-api.js b/lib/routes/bangumi/subject/offcial-subject-api.js index 6226e4140..ac4792b00 100644 --- a/lib/routes/bangumi/subject/offcial-subject-api.js +++ b/lib/routes/bangumi/subject/offcial-subject-api.js @@ -1,5 +1,4 @@ const got = require('@/utils/got'); -const DateTime = require('luxon').DateTime; module.exports = (type) => { const mapping = { @@ -24,7 +23,7 @@ module.exports = (type) => { title: `${article.user.nickname}:${article.title}`, description: article.summary || '', link: article.url, - pubDate: DateTime.fromMillis(article.timestamp * 1000).toRFC2822(), + pubDate: new Date(article.timestamp * 1000).toUTCString(), })), }; }; diff --git a/package.json b/package.json index da384754c..e5a16fc31 100644 --- a/package.json +++ b/package.json @@ -71,7 +71,6 @@ "koa-mount": "4.0.0", "koa-router": "7.4.0", "lru-cache": "5.1.1", - "luxon": "1.16.1", "lz-string": "1.4.4", "markdown-it": "8.4.2", "module-alias": "2.2.0", diff --git a/yarn.lock b/yarn.lock index c29d77d92..7029365d6 100644 --- a/yarn.lock +++ b/yarn.lock @@ -6416,11 +6416,6 @@ lru-cache@^4.0.1, lru-cache@^4.1.2: pseudomap "^1.0.2" yallist "^2.1.2" -luxon@1.16.1: - version "1.16.1" - resolved "https://registry.yarnpkg.com/luxon/-/luxon-1.16.1.tgz#62568d483989fa108f5c87178a05bcc707f7698b" - integrity sha512-3aYYMFpIRdEQJl00ki+NDr2zx/Ulf7ZgohBUb6ifZQuVkP8/KCYJluISl0YNbvZXBdzCbVhpQnS4M6Svjpn7EA== - lz-string@1.4.4: version "1.4.4" resolved "https://registry.yarnpkg.com/lz-string/-/lz-string-1.4.4.tgz#c0d8eaf36059f705796e1e344811cf4c498d3a26"