Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Front matter date format unexpectedly changed during note conversion #398

Open
doxxx93 opened this issue Oct 19, 2024 · 0 comments
Open
Labels
bug Something isn't working

Comments

@doxxx93
Copy link
Contributor

doxxx93 commented Oct 19, 2024

TLDR: Date object in front matter incorrectly stringified during conversion process

Describe the bug

When converting Obsidian notes to another platform using the O2 plugin, the date format in the front matter is unexpectedly changed. The plugin is adding time, timezone, and day of the week information to the date, which was not present in the original front matter.

To Reproduce
Steps to reproduce the behavior:

  1. Create a note in Obsidian with a front matter containing a date field (e.g., date: 2021-01-01)
  2. Use the O2 plugin to convert this note
  3. Check the converted note's front matter

Expected behavior
A clear and concise description of what you expected to happen.

The date in the front matter should remain in the same format as the original, e.g., date: 2021-01-01.

Actual behavior
The date in the front matter is converted to a full date-time string with timezone information, e.g., date: Fri Jan 01 2021 09:00:00 GMT+0900 (Korean Standard Time).

Screenshots
If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

  • OS: [e.g. MacOS]
  • Obsidian version [e.g 1.14.1]
  • O2 Plugin version [e.g. 1.2.x]

Additional context
Additional context

This issue seems to be caused by the implicit conversion of Date objects to strings in the FrontMatterConverter's join function. The conversion is adding unnecessary detail to the date, which may cause issues when the converted notes are used on other platforms.

// in FrontMatterConverter.ts join()

const join = (result: FrontMatter, body: string) => `---
${Object.entries(result)
  .map(([key, value]) => `${key}: ${value}`)
  .join('\n')}
---

${body}`;

The root cause of this issue lies in how JavaScript handles Date objects and string conversions:

  1. Implicit conversion: When converting objects to strings in JavaScript (e.g., using template literals like ${value}), the object's toString() method is called.

  2. Date object's toString(): The toString() method of Date objects returns a full date and time string reflecting the local time zone.

  3. Time zone difference: '2021-01-01T00:00:00.000Z' is in UTC. For Korea (UTC+9), this becomes '2021-01-01 09:00:00' when converted to local time.

  4. Detailed information: toString() includes day of week, full date, time, and time zone information.

@doxxx93 doxxx93 added the bug Something isn't working label Oct 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant