tempo icon indicating copy to clipboard operation
tempo copied to clipboard

[Feature]: Relative time formatting

Open hrynevychroman opened this issue 11 months ago • 7 comments

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 ❤️

hrynevychroman avatar Feb 27 '24 21:02 hrynevychroman

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

A member of the Team first needs to authorize it.

vercel[bot] avatar Feb 27 '24 21:02 vercel[bot]

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?

justin-schroeder avatar Mar 04 '24 14:03 justin-schroeder

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

hrynevychroman avatar Mar 06 '24 15:03 hrynevychroman

@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 avatar Mar 26 '24 13:03 justin-schroeder

@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 🤯

hrynevychroman avatar Mar 27 '24 19:03 hrynevychroman

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?

Serator avatar Apr 23 '24 08:04 Serator

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

peter-emad99 avatar Aug 10 '24 09:08 peter-emad99