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-reliance in LastUpdated #1170

Merged
merged 4 commits into from
Dec 6, 2023

Conversation

tmcw
Copy link
Contributor

@tmcw tmcw commented Nov 29, 2023

Description

Copy link

changeset-bot bot commented Nov 29, 2023

🦋 Changeset detected

Latest commit: 2218038

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

This PR includes changesets to release 1 package
Name Type
@astrojs/starlight 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

Copy link

vercel bot commented Nov 29, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
starlight ✅ Ready (Inspect) Visit Preview Dec 6, 2023 6:31pm

@github-actions github-actions bot added the 🌟 core Changes to Starlight’s main package label Nov 29, 2023
@astrobot-houston
Copy link
Collaborator

Hello! Thank you for opening your first PR to Starlight! ✨

Here’s what will happen next:

  1. Our GitHub bots will run to check your changes.
    If they spot any issues you will see some error messages on this PR.
    Don’t hesitate to ask any questions if you’re not sure what these mean!

  2. In a few minutes, you’ll be able to see a preview of your changes on Vercel 🤩

  3. One or more of our maintainers will take a look and may ask you to make changes.
    We try to be responsive, but don’t worry if this takes a few days.

@kevinzunigacuellar
Copy link
Member

kevinzunigacuellar commented Nov 29, 2023

LGTM!

Edit: The only thing that is missing is a changeset 👍

@tmcw tmcw force-pushed the fix-timezone-last-updated branch from 6a2ddff to c576670 Compare December 5, 2023 20:49
@tmcw
Copy link
Contributor Author

tmcw commented Dec 5, 2023

👍 Added a changeset.

Copy link
Member

@delucis delucis left a comment

Choose a reason for hiding this comment

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

Thanks for the PR @tmcw! And sorry it got buried as we were prepping for Astro v4 and migrating Astro’s Docs to run on Starlight.

Have we tested this works as expected with git-based last updated times as well?

The updated date can come from git or from frontmatter, so ideally it would be great to handle here:

function getLastUpdated({ entry }: PageProps): Date | undefined {
if (entry.data.lastUpdated ?? config.lastUpdated) {
const currentFilePath = fileURLToPath(new URL('src/content/docs/' + entry.id, project.root));
let date = typeof entry.data.lastUpdated !== 'boolean' ? entry.data.lastUpdated : undefined;
if (!date) {
try {
({ date } = getFileCommitDate(currentFilePath, 'newest'));
} catch {}
}
return date;
}
return;
}

This would also mean anyone overriding this component would get the correct behaviour without having to replicate this logic. May not be possible though given we’re providing a Date object in route data.

@kevinzunigacuellar
Copy link
Member

kevinzunigacuellar commented Dec 6, 2023

I don't think that the issue is that the Date object is wrong. It just displays the wrong time when its converted to a string because it adjusts to the local timezone. I fear that changing the date object upstream might result in unexpected date behavior for users.

Copy link
Member

@delucis delucis left a comment

Choose a reason for hiding this comment

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

Yeah, you’re probably right @kevinzunigacuellar! Let’s give it a try and if anyone notices broken behaviour with this change, hopefully they’ll let us know — thanks again @tmcw 🙌

.changeset/new-starfishes-accept.md Outdated Show resolved Hide resolved
@delucis delucis merged commit bcc2301 into withastro:main Dec 6, 2023
7 checks passed
@astrobot-houston astrobot-houston mentioned this pull request Dec 6, 2023
HiDeoo added a commit to HiDeoo/starlight that referenced this pull request Dec 13, 2023
* main: (440 commits)
  i18n(fr): update `getting-started.mdx` (withastro#1245)
  [ci] format
  docs(showcase): add csmos.space (withastro#1269)
  [ci] format
  docs: add SiteOne Crawler to showcase (withastro#1264)
  Fix formatting
  [ci] format
  docs(i18n): Add Indonesian translation for site search documentation (withastro#1250)
  i18n(es): fix typo (withastro#1246)
  i18n(ja): Update getting-started.mdx (withastro#1252)
  i18n(es): Update `getting-started.mdx` (withastro#1247)
  i18n(ko-KR): update `getting-started.mdx` (withastro#1248)
  Update upgrade instructions to show new `@astrojs/upgrade` (withastro#1241)
  [ci] format
  [ci] release (withastro#1240)
  i18n(ru): Fix typo in `i18n.untranslatedContent` (withastro#1243)
  Fix timezone-reliance in LastUpdated (withastro#1170)
  Prefetch links on hover by default (withastro#1242)
  Add support for Astro v4, drop support for Astro v3 (withastro#1238)
  Add Matrix social icon (withastro#1203)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🌟 core Changes to Starlight’s main package
Projects
None yet
Development

Successfully merging this pull request may close these issues.

lastUpdated displays incorrect date
5 participants