Skip to content

Commit

Permalink
Desktop: Resolves laurent22#9683: Frontmatter importer: Support Notes…
Browse files Browse the repository at this point in the history
…nook-style timestamps
  • Loading branch information
personalizedrefrigerator committed Jan 7, 2024
1 parent 2bf2395 commit c9f22f0
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
title: "Frontmatter test"
created_at: 01-01-2024 01:23 AM
updated_at: 02-01-2024 04:56 AM
---

# Frontmatter test

A test note with frontmatter.
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,13 @@ describe('InteropService_Importer_Md_frontmatter: importMetadata', () => {
expect(note.title).toBe('Distill for R Markdown');
expect(note.author).toBe('JJ Allaire');
});
it('should import Notesnook files with created and update timestamps', async () => {
const note = await importTestFile('notesnook_updated_created.md');

expect(note.title).toBe('Frontmatter test');
expect(note.user_created_time).toBe(Date.parse('2024-01-01T01:23:00.000'));
expect(note.user_updated_time).toBe(Date.parse('2024-01-02T04:56:00.000'));
});
it('should handle date formats with timezone information', async () => {
const note = await importTestFile('utc.md');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,9 @@ export default class InteropService_Importer_Md_frontmatter extends InteropServi
metadata['user_created_time'] = time.anythingToMs(md['created'], Date.now());
} else if ('date' in md) {
metadata['user_created_time'] = time.anythingToMs(md['date'], Date.now());
} else if ('created_at' in md) {
// Add support for Notesnook
metadata['user_created_time'] = time.anythingToMs(md['created_at'], Date.now());
}

if ('updated' in md) {
Expand All @@ -120,6 +123,9 @@ export default class InteropService_Importer_Md_frontmatter extends InteropServi
metadata['user_updated_time'] = time.anythingToMs(md['lastmod'], Date.now());
} else if ('date' in md) {
metadata['user_updated_time'] = time.anythingToMs(md['date'], Date.now());
} else if ('updated_at' in md) {
// Notesnook
metadata['user_updated_time'] = time.anythingToMs(md['updated_at'], Date.now());
}

if ('latitude' in md) { metadata['latitude'] = md['latitude']; }
Expand Down

0 comments on commit c9f22f0

Please sign in to comment.