Skip to content

Commit

Permalink
add date migration
Browse files Browse the repository at this point in the history
  • Loading branch information
Chuanqi committed Aug 20, 2023
1 parent e3dd577 commit 4bb928f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
9 changes: 9 additions & 0 deletions packages/tools/markdown-converter/lib.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,15 @@ export function handleHeaderLines(haikuFile, headerLines) {
value = `"${value}"`;
}

if (key === "created") {
const date = new Date(value);
const shortLocalDate = `${date.getFullYear()}-${(date.getMonth() + 1).toString().padStart(2, "0")}-${date
.getDate()
.toString()
.padStart(2, "0")}`;
return `${key}: ${shortLocalDate}`;
}

if (key === "tags") {
const tags = value
.split(",")
Expand Down
11 changes: 11 additions & 0 deletions packages/tools/markdown-converter/lib.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,17 @@ describe("header", () => {
);
});

it("coverts date", () => {
assert.strictEqual(
handleHeaderLines("", fileToLines(`#+title: hello\n#+created: 2023-08-19T23:59:59-07:00`).headerLines),
`---\ntitle: hello\ncreated: 2023-08-19\n---`
);
assert.strictEqual(
handleHeaderLines("", fileToLines(`#+title: hello\n#+created: 2023-08-19T00:00:01-07:00`).headerLines),
`---\ntitle: hello\ncreated: 2023-08-19\n---`
);
});

it("empty tags", () => {
assert.strictEqual(
handleHeaderLines("", fileToLines(`#+title: hello\n#+tags: `).headerLines),
Expand Down

0 comments on commit 4bb928f

Please sign in to comment.