cdaven / tiddlywiki-stuff

My TiddlyWiki macros and plugins.
MIT License
10 stars 2 forks source link

Date format not ISO when exporting via tiddlywiki CLI #9

Open hissohathair opened 1 month ago

hissohathair commented 1 month ago

When exporting with the TW CLI I get dates in the frontmatter formatted differently from when I use TW in the browser.

For example, I added a new tiddler "TestPage/FrontMatter" and expected the following:

title: 'TestPage/FrontMatter'
date: '2024-06-23T08:30:50.917Z'
tags: ['Another Tag', 'Tag2', 'TestData']
created: '2024-06-23T08:22:18.552Z'

When using TW in the browser to export to Markdown I get that data. But when I use TW using the CLI I get:

title: 'TestPage/FrontMatter'
tags: ['Another Tag', 'Tag2', 'TestData']
created: 'Sun Jun 23 2024 18:22:18 GMT+1000 (Australian Eastern Standard Time)'

Attaching a modified test.ps1 to contains this test case: test.ps1.txt (had to rename to ".txt" for GH to let me upload it :-) -- can also find here)

I am looking into it but so far don't understand the root cause. The render-rules.ts file is definitely calling .toISOString() on the appropriate field, so JS has parsed it as a date just fine. Just for some reason in a node.js context the date is not actually ISO formatted. The other thing to note is the missing date field, that seems to be because it's not an instanceof Date but again that only happens when running from CLI.

Any ideas? In the meantime I will keep digging...

hissohathair commented 1 month ago

Ah...might be TW being helpful: https://tiddlywiki.com/static/DateFormat.html

hissohathair commented 1 month ago

Have a possible fix here: https://github.com/hissohathair/tiddlywiki-stuff/tree/frontmatter-fix

Haven't raised a PR yet because although the patch passes the test case I'm not 100% sure I understand why it's happening in the first place. Also want to be sure I haven't broken the in-browser behaviour...

hissohathair commented 1 month ago

Have a better patch now and a few more tests to make sure I am not making things worse. :-)

Have a better understanding of the issue. instanceof Date returns false when running under Node, although the object is indeed a Date object (just not the same kind of Date I guess), so changing the test to checking for a .toISOString member resolves the issue.