Skip to content

Commit

Permalink
fix: date format issue
Browse files Browse the repository at this point in the history
  • Loading branch information
sywhb committed Feb 17, 2023
1 parent 2b96c1a commit 918665d
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 9 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
},
"dependencies": {
"@logseq/libs": "^0.0.10",
"date-fns": "^2.29.3",
"diff-match-patch": "^1.0.5",
"logseq-dateutils": "^0.0.22",
"luxon": "^3.0.1",
"markdown-escape": "^1.1.0",
"mustache": "^4.2.0"
Expand Down
6 changes: 3 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import {
LSPluginBaseInfo,
SettingSchemaDesc,
} from '@logseq/libs/dist/LSPlugin'
import { getDateForPage } from 'logseq-dateutils'
import {
Article,
compareHighlightsInFile,
Expand All @@ -16,6 +15,7 @@ import {
PageType,
parseDateTime,
DATE_FORMAT,
formatDate,
} from './util'
import { DateTime } from 'luxon'
import { render } from 'mustache'
Expand Down Expand Up @@ -165,7 +165,7 @@ const fetchOmnivore = async (inBackground = false) => {
for (const article of articles) {
const siteName =
article.siteName || siteNameFromUrl(article.originalArticleUrl)
const dateSaved = getDateForPage(
const dateSaved = formatDate(
new Date(article.savedAt),
preferredDateFormat
)
Expand Down Expand Up @@ -207,7 +207,7 @@ const fetchOmnivore = async (inBackground = false) => {
text: it.quote,
labels: it.labels,
highlightUrl: `https://omnivore.app/me/${article.slug}#${it.id}`,
dateHighlighted: getDateForPage(
dateHighlighted: formatDate(
new Date(it.updatedAt),
preferredDateFormat
),
Expand Down
5 changes: 5 additions & 0 deletions src/util.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { diff_match_patch } from 'diff-match-patch'
import { DateTime } from 'luxon'
import escape from 'markdown-escape'
import { format } from 'date-fns'

export const DATE_FORMAT_W_OUT_SECONDS = "yyyy-MM-dd'T'HH:mm"
export const DATE_FORMAT = `${DATE_FORMAT_W_OUT_SECONDS}:ss`
Expand Down Expand Up @@ -196,3 +197,7 @@ export const parseDateTime = (str: string): DateTime => {
}
return DateTime.fromFormat(str, DATE_FORMAT_W_OUT_SECONDS)
}

export const formatDate = (date: Date, preferredDateFormat: string): string => {
return `[[${format(date, preferredDateFormat)}]]`
}
10 changes: 5 additions & 5 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1970,6 +1970,11 @@ [email protected]:
resolved "https://registry.yarnpkg.com/csstype/-/csstype-3.1.0.tgz#4ddcac3718d787cf9df0d1b7d15033925c8f29f2"
integrity sha512-uX1KG+x9h5hIJsaKR9xHUeUraxf8IODOwq9JLNPq6BwB04a/xgpq3rcx47l5BZu5zBPlgD342tdke3Hom/nJRA==

date-fns@^2.29.3:
version "2.29.3"
resolved "https://registry.yarnpkg.com/date-fns/-/date-fns-2.29.3.tgz#27402d2fc67eb442b511b70bbdf98e6411cd68a8"
integrity sha512-dDCnyH2WnnKusqvZZ6+jA1O51Ibt8ZMRNkDZdyAyK4YfbDwa/cEmuztzG5pk6hqlp9aSBPYcjOlktquahGwGeA==

dateformat@^3.0.0:
version "3.0.3"
resolved "https://registry.npmjs.org/dateformat/-/dateformat-3.0.3.tgz"
Expand Down Expand Up @@ -3375,11 +3380,6 @@ [email protected]:
chalk "^4.1.0"
is-unicode-supported "^0.1.0"

logseq-dateutils@^0.0.22:
version "0.0.22"
resolved "https://registry.npmjs.org/logseq-dateutils/-/logseq-dateutils-0.0.22.tgz"
integrity sha512-6cJq2eVQONG2dloNDg+US4j+QYwo0XXzcq5x9m9/pQAmobAwnaN6PD/4iY4sOAkuPzapZBs3FffFFEy+R1f5fA==

loupe@^2.3.1:
version "2.3.6"
resolved "https://registry.yarnpkg.com/loupe/-/loupe-2.3.6.tgz#76e4af498103c532d1ecc9be102036a21f787b53"
Expand Down

0 comments on commit 918665d

Please sign in to comment.