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

feat: add LocaleDateTime for markdown time #12426

Merged
merged 1 commit into from
Mar 12, 2024
Merged

feat: add LocaleDateTime for markdown time #12426

merged 1 commit into from
Mar 12, 2024

Conversation

wackerow
Copy link
Member

@wackerow wackerow commented Mar 11, 2024

Description

  • Adds a component that parses a date/time string for use within static Markdown pages
  • Component mapped to time html element in MdComponents for use within markdown pages
  • Accepts utcDateTime prop which will be parsed as a Date object
  • Accepts a hideDate OR hideTime prop to optionally hide one half of the resulting string
  • Accepts optional options override to customize styling if needed

Example usage

This PR only adds the component but does not implement it anywhere.

Example of how to use would be <time utcDateTime="2024-04-20T01:00:00Z" /> inside a markdown file, which would render as April 19, 2024 at 9:00:00 PM for Eastern US timezone. Adding hideTime would result in April 19, 2024, and adding hideDate would render as 6:00:00 PM. A different locale would adjust accordingly.

Related Issue

Summary by CodeRabbit

  • New Features
    • Introduced a LocaleDateTime component for displaying date and time in a localized format with customization options.

Copy link
Contributor

coderabbitai bot commented Mar 11, 2024

Walkthrough

This change introduces a new LocaleDateTime component to render dates and times in the user's local timezone, addressing the issue of static markdown dates/times. The component is flexible, allowing for the hiding of either date or time portions and supports customization of formatting. Additionally, it ensures that date and time are not hidden simultaneously. The component is then integrated into the MdComponents for use within markdown-rendered content, enhancing the site's internationalization capabilities.

Changes

File Path Change Summary
src/components/LocaleDateTime.tsx Introduced LocaleDateTime component for rendering localized date and time.
src/components/.../MdComponents.tsx Imported LocaleDateTime and added it to htmlElements for markdown content localization.

Assessment against linked issues

Objective Addressed Explanation
Markdown dates/times are not timezone responsive (#12425)

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share

Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit-tests for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit tests for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit tests.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/coderabbit-overrides.v2.json

CodeRabbit Discord Community

Join our Discord Community to get help, request features, and share feedback.

Copy link

netlify bot commented Mar 11, 2024

Deploy Preview for ethereumorg ready!

Name Link
🔨 Latest commit ec3f0d9
🔍 Latest deploy log https://app.netlify.com/sites/ethereumorg/deploys/65ef5518f75aa50008479570
😎 Deploy Preview https://deploy-preview-12426--ethereumorg.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 2

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 2ce32ca and ec3f0d9.
Files selected for processing (2)
  • src/components/LocaleDateTime.tsx (1 hunks)
  • src/components/MdComponents.tsx (2 hunks)
Additional comments: 7
src/components/LocaleDateTime.tsx (6)
  • 3-8: The LocaleDateTimeProps type definition is clear and well-documented through the prop names. However, it might be beneficial to include comments for each prop, especially for options to clarify what kind of options are expected here, as they directly relate to Intl.DateTimeFormatOptions.
  • 29-29: Using useRouter from Next.js to determine the locale is a smart approach for localization. This ensures that the date and time are formatted according to the user's locale, enhancing the user experience for international users.
  • 31-40: The default options for date and time formatting (defaultDateOptions and defaultTimeOptions) are well-chosen, covering the most common elements of a date and time. This ensures that, by default, the component will render a comprehensive and understandable date-time string for users.
  • 41-44: The merging of defaultDateOptions, defaultTimeOptions, and user-provided options is done elegantly, allowing for a high degree of customization while maintaining sensible defaults. This pattern is a good practice for components that need to balance flexibility with ease of use.
  • 47-49: The use of the <time> HTML element with both dateTime and the formatted string is semantically correct and enhances the accessibility of the website. This is a good practice for date and time representation in HTML.
  • 53-53: Exporting the LocaleDateTime component as a default export is consistent with the module system in React. This makes it easy to import and use the component elsewhere in the project.
src/components/MdComponents.tsx (1)
  • 43-43: Importing the LocaleDateTime component is done correctly. This ensures that the component is available for use within the MdComponents file, which is crucial for its integration into the markdown rendering process.

Comment on lines +24 to +27
if (hideDate && hideTime)
throw new Error(
"LocaleDateTime hideDate and hideTime props cannot both be true"
)
Copy link
Contributor

@coderabbitai coderabbitai bot Mar 11, 2024

Choose a reason for hiding this comment

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

Throwing an error when both hideDate and hideTime are true is a good safeguard against misuse of the component. However, consider the user experience on the website if this error occurs. It might be more user-friendly to log a warning and default to showing both date and time, or just the date, instead of throwing an error that could potentially break the page rendering.

Copy link
Member

Choose a reason for hiding this comment

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

Agree with the rabbit @wackerow, this should log but not throw

Copy link
Contributor

Choose a reason for hiding this comment

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

Seems like the humans are having a chat. I'll hop back into my burrow for now. If you need me again, just tag @coderabbitai in a new comment, and I'll come hopping out!

src/components/MdComponents.tsx Show resolved Hide resolved
Copy link
Member

@nhsz nhsz left a comment

Choose a reason for hiding this comment

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

@wackerow thanks, asking to remove the throw and left a question

Comment on lines +24 to +27
if (hideDate && hideTime)
throw new Error(
"LocaleDateTime hideDate and hideTime props cannot both be true"
)
Copy link
Member

Choose a reason for hiding this comment

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

Agree with the rabbit @wackerow, this should log but not throw

src/components/LocaleDateTime.tsx Show resolved Hide resolved
@nhsz nhsz merged commit 31dccb7 into dev Mar 12, 2024
9 of 10 checks passed
@nhsz nhsz deleted the markdown-date branch March 12, 2024 21:06
This was referenced Mar 13, 2024
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.

Markdown dates/times are not timezone responsive
2 participants