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

[Feature]: Relative time formatting #27

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

hrynevychroman
Copy link
Contributor

This PR will close #7

@justin-schroeder made this as draft, need review and some help with timezones, also now we relative time for now only, but maybe we need to expand it to different date optionally?

Will wait for your thoughts, and update all then ❤️

Copy link

vercel bot commented Feb 27, 2024

@romanhrynevych is attempting to deploy a commit to the Formkit Team on Vercel.

A member of the Team first needs to authorize it.

@justin-schroeder
Copy link
Member

Thanks for this head start @romanhrynevych — one thing I would like to explore (or rule out as an option) is the ability to not only format but also parse relative time. Given an anchor date, a relative time string, and locale — can we reverse it back to a date object?

@hrynevychroman
Copy link
Contributor Author

hrynevychroman commented Mar 6, 2024

@justin-schroeder Sorry, but I don't clearly understand. Could you please provide some code examples and explain what they need to show? ❤️

@justin-schroeder
Copy link
Member

justin-schroeder commented Mar 26, 2024

@romanhrynevych basically I’d like tempo to be able to parse anything it formats, and format anything it parses. This allows users to create bi-directional interfaces which is a real-world use case I often have myself. A basic example:

TZ=UTC
formatRelative(date: '2024-03-25', options: { unit: 'day' }, originDate: '2025-03-24') // output: tomorrow
parseRelative('tomorrow', options: { unit: 'day' }, originDate: '2025-03-24') // output: Date('2024-03-25T00:00:00Z')

Obviously origin date would default to now and would often not be required, but im very interested in researching if this kind of bi-directional format/parse is possible in the same way that we do it with format/parse

@hrynevychroman
Copy link
Contributor Author

hrynevychroman commented Mar 27, 2024

@romanhrynevych basically I’d like tempo to be able to parse anything it formats, and format anything it parses. This allows users to create bi-directional interfaces which is a real-world use case I often have myself. A basic example:

TZ=UTC
formatRelative(date: '2024-03-25', options: { unit: 'day' }, originDate: '2025-03-24') // output: tomorrow
parseRelative('tomorrow', options: { unit: 'day' }, originDate: '2025-03-24') // output: Date('2024-03-25T00:00:00Z')

Obviously origin date would default to now and would often not be required, but im very interested in researching if this kind of bi-directional format/parse is possible in the same way that we do it with format/parse

@justin-schroeder great idea but I don't think how to implement it 😞 Now we have wrapper around native functions, receive different locale, languages etc. But how we can parse it, if, for example, this library will be used in ukrainian project, parseRelative('вчора') 😁 . If to implement it need to reverse IntlRelativeTime, so much time, bugs, ahhh 🤯

@Serator
Copy link

Serator commented Apr 23, 2024

Hi guys. This long awaited feature seems to be stalled due to a rather non-trivial issue. Maybe it's possible to separate relative time parsing into a separate issue and release relative time formatting features soon?

@peter-emad99
Copy link

any plan for this feature to get it's way to the package ?

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.

Feature Request: Relative Time
4 participants