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] Support RelativeTimeFormat #128

Open
oritwoen opened this issue Jun 26, 2023 · 2 comments
Open

[Feat] Support RelativeTimeFormat #128

oritwoen opened this issue Jun 26, 2023 · 2 comments
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@oritwoen
Copy link

🆒 Your use case

It would be nice to have a built-in option to display the time in a relative form without creating additional functions.

🆕 The solution you'd like

Implement https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat#constructor

🔍 Alternatives you've considered

No response

ℹ️ Additional info

No response

@oritwoen oritwoen added the enhancement New feature or request label Jun 26, 2023
@danielroe danielroe added the good first issue Good for newcomers label Feb 1, 2024
@keystrm
Copy link

keystrm commented Mar 24, 2024

Hi, I just started working on this feature. Here are the problems I've encountered and the solutions I've implemented so far:

  1. I'm curious about how we manage the date format we display. Specifically, if someone needs to show the time in 'relativeTimeFormat', how can it be detected?
    I created a prop named 'relative' to determine the time format, then I conditionally render the output based on this.

  2. How do we calculate the relative date?
    I display the relative date according to the current date, meaning I calculate the time difference between the 'datetime' from the prop and the current date, and display that difference as the output.

  3. How do we determine the date format for this relative time format?
    As we need to include 'day', 'quarter', etc., in the function. Should we automatically determine this or should we get that as user input? Currently, I have just calculated the time difference in days for testing purposes.

This is my approach so far; please correct me if I am approaching this the wrong way. I'm attaching a screenshot of the output below

image

@danielroe
Copy link
Owner

I think we would expect the user to pick the relative format they need and we can use this as the flag (so relative prop would expect a string or object).

and yes, I expect it would show date from current date unless another date is provided by user.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

3 participants