tempo
tempo copied to clipboard
[Feature]: Relative time formatting
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 ❤️
@romanhrynevych is attempting to deploy a commit to the Formkit Team on Vercel.
A member of the Team first needs to authorize it.
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 Sorry, but I don't clearly understand. Could you please provide some code examples and explain what they need to show? ❤️
@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
@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 🤯
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?
any plan for this feature to get it's way to the package ?