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 date representation (again) #1426

Closed
wants to merge 8 commits into from

Conversation

agoose77
Copy link
Contributor

@agoose77 agoose77 commented Aug 7, 2024

Presently, our datetime handling is not quite right. We sometimes (due to Date) parse dates in the local timezone, but we render them in templates as UTC.

i.e. for BST=UTC+1

> // A valid UTC date
> new Date(Date.UTC(2024, 6, 1))
2024-07-01T00:00:00.000Z
> // The same date without UTC
> new Date(2024, 6, 1)
2024-06-30T23:00:00.000Z

where the Z suffix indicates UTC. At the moment, we then ask for getUTCDate(), which returns 30 because the code parses the date as the 00:00:00 timestamp in BST, which is 23:00:00 the previous day in UTC.

Instead, we should assume that a user is entering a valid "local"/"wall time" date. This PR fixes mystmd's validation to explicitly ignore timezones and directly take the day/month information from the Date object.

Should fix #1357

See also https://tc39.es/proposal-temporal/docs/ambiguity.html

@agoose77 agoose77 requested a review from rowanc1 August 7, 2024 13:15
Copy link

changeset-bot bot commented Aug 7, 2024

🦋 Changeset detected

Latest commit: 034a329

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
simple-validators Patch
myst-templates Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@agoose77 agoose77 requested review from fwkoch and removed request for rowanc1 August 7, 2024 13:50
@@ -76,7 +76,7 @@ cases:
affiliations:
- id: univa
name: University A
date: 14 Dec 2021
date: '2021-12-14'
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Escape YAML interpretation

@agoose77
Copy link
Contributor Author

agoose77 commented Aug 19, 2024

Ugh, yikes, more problems:

When the time zone offset is absent, date-only forms are interpreted as a UTC time and date-time forms are interpreted as local time. This is due to a historical spec error that was not consistent with ISO 8601 but could not be changed due to web compatibility. See Broken Parser – A Web Reality Issue.

i.e.

> process.env.TZ = "America/Anchorage"
'America/Anchorage'
> new Date("2024-06-06")
2024-06-06T00:00:00.000Z
> new Date("2024-06-06 19:00")
2024-06-07T03:00:00.000Z

We really need a better way to handle this. I'll update the main body of the PR dsecription.

@agoose77
Copy link
Contributor Author

I think we can use moment.js's parseZone function. This assumes ambiguous input is UTC, and non-ambiguous input keeps the timezone. In other words, there's no timezone shift happening, which means we can use the raw-parsed components.

@agoose77 agoose77 marked this pull request as draft August 19, 2024 16:55
@agoose77
Copy link
Contributor Author

The history of this PR will be confusing. I'll open a new one!

@agoose77 agoose77 closed this Aug 20, 2024
@rowanc1 rowanc1 deleted the agoose77/fix-date-representation branch August 22, 2024 22:07
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.

date rendering is a little off
1 participant