according to a good friend, the moment for moment has passed. I should move on to something cool! like day.js?
This commit is contained in:
parent
896b965879
commit
819f8528b6
|
@ -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/",
|
||||
|
|
|
@ -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.
|
||||
|
||||
|
|
|
@ -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": {
|
||||
|
|
|
@ -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")
|
||||
|
|
|
@ -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")
|
|
@ -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`)
|
||||
|
|
16
yarn.lock
16
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"
|
||||
|
|
Loading…
Reference in New Issue