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

fix: timezone issue with ISO dates #1614

Draft
wants to merge 1 commit into
base: v4
Choose a base branch
from

Conversation

linusrachlis
Copy link

@linusrachlis linusrachlis commented Nov 24, 2024

If the date is in YYYY-MM-DD format, which is the default for the Obsidian 'date' file property, it will be interpreted as UTC midnight rather than local time midnight. If the local timezone is at a negative GMT offset, this means it will render incorrectly as the previous day when passed to 'getLocaleDateString'.

Adding a time to the input string before passing to the Date() constructor makes it interpret the string as midnight in the local timezone instead so it will render as expected.

⚠️ This draft PR a hacky fix, currently just for illustration purposes. ⚠️

Context:

When the time zone offset is absent, date-only forms are interpreted as a UTC time and date-time forms are interpreted as a local time. The interpretation as a UTC time is due to a historical spec error that was not consistent with ISO 8601 but could not be changed due to web compatibility.
-- MDN

If the date is in YYYY-MM-DD format, which is the default for the Obsidian 'date' file property, it
will be interpreted as UTC midnight which will mean it renders incorrectly as the previous day when
passed to 'getLocaleDateString'. Adding a time makes it interpret as midnight in the local timezone
instead so it will render as expected.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant