From 819f8528b632fc358cc208e4c45f2b917930e6cc Mon Sep 17 00:00:00 2001 From: wgroeneveld Date: Fri, 5 Mar 2021 21:23:34 +0100 Subject: [PATCH] according to a good friend, the moment for moment has passed. I should move on to something cool! like day.js? --- .pnp.js | 22 +++++++++++----------- README.md | 4 ++-- package.json | 4 ++-- src/masto-feed-parser.js | 8 +++++--- test/{moment.test.js => dateparse.test.js} | 8 +++++--- test/masto-feed-parser.test.js | 4 ++-- yarn.lock | 16 ++++++++-------- 7 files changed, 35 insertions(+), 31 deletions(-) rename test/{moment.test.js => dateparse.test.js} (64%) diff --git a/.pnp.js b/.pnp.js index e4de20d..cad9e48 100755 --- a/.pnp.js +++ b/.pnp.js @@ -37,13 +37,13 @@ function $$SETUP_STATE(hydrateRuntimeState, basePath) { [null, { "packageLocation": "./", "packageDependencies": [ + ["dayjs", "npm:1.10.4"], ["ent", "npm:2.2.0"], ["fast-xml-parser", "npm:3.18.0"], ["got", "npm:11.8.2"], ["howlongtobeat", "npm:1.3.1"], ["jest", "npm:26.6.3"], ["lunr", "npm:2.3.9"], - ["moment", "npm:2.29.1"], ["parser-front-matter", "npm:1.6.4"] ], "linkType": "SOFT", @@ -2036,6 +2036,15 @@ function $$SETUP_STATE(hydrateRuntimeState, basePath) { "linkType": "HARD", }] ]], + ["dayjs", [ + ["npm:1.10.4", { + "packageLocation": "./.yarn/cache/dayjs-npm-1.10.4-e450424eab-3b7bb2232f.zip/node_modules/dayjs/", + "packageDependencies": [ + ["dayjs", "npm:1.10.4"] + ], + "linkType": "HARD", + }] + ]], ["debug", [ ["npm:2.6.9", { "packageLocation": "./.yarn/cache/debug-npm-2.6.9-7d4cb597dc-559f44f98c.zip/node_modules/debug/", @@ -3518,13 +3527,13 @@ function $$SETUP_STATE(hydrateRuntimeState, basePath) { "packageLocation": "./", "packageDependencies": [ ["jam-my-stack", "workspace:."], + ["dayjs", "npm:1.10.4"], ["ent", "npm:2.2.0"], ["fast-xml-parser", "npm:3.18.0"], ["got", "npm:11.8.2"], ["howlongtobeat", "npm:1.3.1"], ["jest", "npm:26.6.3"], ["lunr", "npm:2.3.9"], - ["moment", "npm:2.29.1"], ["parser-front-matter", "npm:1.6.4"] ], "linkType": "SOFT", @@ -4507,15 +4516,6 @@ function $$SETUP_STATE(hydrateRuntimeState, basePath) { "linkType": "HARD", }] ]], - ["moment", [ - ["npm:2.29.1", { - "packageLocation": "./.yarn/cache/moment-npm-2.29.1-787d9fdafd-86729013fe.zip/node_modules/moment/", - "packageDependencies": [ - ["moment", "npm:2.29.1"] - ], - "linkType": "HARD", - }] - ]], ["ms", [ ["npm:2.0.0", { "packageLocation": "./.yarn/cache/ms-npm-2.0.0-9e1101a471-1a230340cc.zip/node_modules/ms/", diff --git a/README.md b/README.md index 6a7fd9c..5dbeccc 100644 --- a/README.md +++ b/README.md @@ -27,13 +27,13 @@ Usage example: await mastodon.parseFeed({ notesdir: `${__dirname}/content/notes`, url: "https://chat.brainbaking.com/users/wouter/feed", - utcOffset: "+01:00" + utcOffset: 60 }) ``` Default values: -- `utcOffset`: `"+01:00"` (because that's where I am!) +- `utcOffset`: `60` (= GMT+1, that's where I am!) (in **minutes**, see [day.js docs](https://day.js.org/docs/en/manipulate/utc-offset) Note that this **does not** delete the notes dir with every call. It simply checks if there isn't already a file with the same name (based on the publication date), and adds one if not. diff --git a/package.json b/package.json index 03fee9d..5f942c0 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "jam-my-stack", - "version": "1.0.4", + "version": "1.0.5", "repository": { "url": "https://github.com/wgroeneveld/jam-my-stack", "type": "git" @@ -12,12 +12,12 @@ "test": "jest" }, "dependencies": { + "dayjs": "^1.10.4", "ent": "^2.2.0", "fast-xml-parser": "^3.18.0", "got": "^11.8.2", "howlongtobeat": "^1.3.1", "lunr": "^2.3.9", - "moment": "^2.29.1", "parser-front-matter": "^1.6.4" }, "devDependencies": { diff --git a/src/masto-feed-parser.js b/src/masto-feed-parser.js index 75d8d08..156cd30 100644 --- a/src/masto-feed-parser.js +++ b/src/masto-feed-parser.js @@ -3,7 +3,9 @@ const parser = require("fast-xml-parser"); const { writeFileSync, existsSync, mkdirSync } = require('fs'); const ent = require('ent') const { getFiles } = require('./file-utils'); -const moment = require('moment') +const dayjs = require('dayjs') +const utc = require('dayjs/plugin/utc') +dayjs.extend(utc) function stripBeforeThirdSlash(str) { const splitted = str.split('/') @@ -38,7 +40,7 @@ ${item.content} // utcOffset = "+01:00" async function parseMastoFeed(options) { - const { notesdir, url, utcOffset = "+01:00" } = options + const { notesdir, url, utcOffset = 60 } = options const notesroot = await getFiles(notesdir) const notes = notesroot @@ -55,7 +57,7 @@ async function parseMastoFeed(options) { ignoreAttributes: false }) const items = root.feed.entry.map(item => { - const date = moment.utc(item.published).utcOffset(utcOffset) + const date = dayjs.utc(item.published).utcOffset(utcOffset) const year = date.format("YYYY") const month = date.format("MM") const day = date.format("DD") diff --git a/test/moment.test.js b/test/dateparse.test.js similarity index 64% rename from test/moment.test.js rename to test/dateparse.test.js index edd63ad..414a675 100644 --- a/test/moment.test.js +++ b/test/dateparse.test.js @@ -1,12 +1,14 @@ // momentjs verification tests -const moment = require('moment') +var dayjs = require('dayjs') +const utc = require('dayjs/plugin/utc') +dayjs.extend(utc) test('momentjs from UTC to UTC+1', () => { - const date = moment + const date = dayjs .utc("2021-03-02T16:13:27.921888Z") - .utcOffset("+01:00") + .utcOffset(60) expect(date.format("YYYY-MM-DD")).toEqual("2021-03-02") expect(date.format("HH-mm-ss")).toEqual("17-13-27") diff --git a/test/masto-feed-parser.test.js b/test/masto-feed-parser.test.js index 81bc35e..178d11b 100644 --- a/test/masto-feed-parser.test.js +++ b/test/masto-feed-parser.test.js @@ -33,7 +33,7 @@ describe("mastodon feed parser tests", () => { await parseMastoFeed({ url: "invalid", notesdir: dumpdir, - utcOffset: "+00:00" + utcOffset: 0 }) const actualMd = (await fsp.readFile(`${dumpdir}/2021/03/01h19m03s35.md`)).toString() @@ -45,7 +45,7 @@ describe("mastodon feed parser tests", () => { await parseMastoFeed({ url: "invalid", notesdir: dumpdir, - utcOffset: "+00:00" + utcOffset: 0 }) const actualMd = await fsp.readFile(`${dumpdir}/2021/03/02h16m18s46.md`) diff --git a/yarn.lock b/yarn.lock index e8452f6..12c6c1b 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1630,6 +1630,13 @@ __metadata: languageName: node linkType: hard +"dayjs@npm:^1.10.4": + version: 1.10.4 + resolution: "dayjs@npm:1.10.4" + checksum: 3b7bb2232fff808209870bc72d4b2000941a1aa45f0226e2907f9dd1dda306d4b3a1eb9058450fd2c324b01a007a37809ac6f9b525806a86902c55e2934cd5d5 + languageName: node + linkType: hard + "debug@npm:^2.2.0, debug@npm:^2.3.3": version: 2.6.9 resolution: "debug@npm:2.6.9" @@ -2940,13 +2947,13 @@ fsevents@^2.1.2: version: 0.0.0-use.local resolution: "jam-my-stack@workspace:." dependencies: + dayjs: ^1.10.4 ent: ^2.2.0 fast-xml-parser: ^3.18.0 got: ^11.8.2 howlongtobeat: ^1.3.1 jest: ^26.6.3 lunr: ^2.3.9 - moment: ^2.29.1 parser-front-matter: ^1.6.4 languageName: unknown linkType: soft @@ -3827,13 +3834,6 @@ fsevents@^2.1.2: languageName: node linkType: hard -"moment@npm:^2.29.1": - version: 2.29.1 - resolution: "moment@npm:2.29.1" - checksum: 86729013febf7160de5b93da69273dd304d674b0224f9544b3abd09a87671ddd2cdd57598261ce57588910d63747ffd5590965e83c790d8bf327083c0e0a06e0 - languageName: node - linkType: hard - "ms@npm:2.0.0": version: 2.0.0 resolution: "ms@npm:2.0.0"