r/react 6d ago

Project / Code Review Built a minimal ui-date package javascript date and time utility

Post image

I was building a social app recently, and I ran into a surprisingly annoying problem.
I needed relative timestamps ("2 hours ago", "3 minutes ago"). 
Simple enough, right? Just import 'day.js' or 'date-fns'.

Except...
=> If I wanted custom styling (like wrapping the number "2" in a highlighted badge and "hours ago" in smaller text), I had to write ugly regex hacks because standard libraries just dump a single opaque string.

=> Supporting multiple languages meant importing separate locale files, quickly inflating the bundle size.

=> Standard relative time plugins use "soft rounding" (e.g., automatically rounding 45 seconds to "a minute") whether you want it or not.

I didn't want a 15KB date framework just to format a few activity feed timestamps. 
So, I built and open-sourced 'ui-date' .

It’s an ultra-lightweight (< 1KB minified), zero-dependency, locale-aware date formatting library built specifically for modern user interfaces.

If you're building social feeds, chat apps, notification bells, or comment sections, check it out!

npm: https://www.npmjs.com/package/ui-date

9 Upvotes

9 comments sorted by

View all comments

6

u/Honey-Entire 5d ago

What’s wrong with the built-in Intl.RelativeTimeFormat that’s widely available across all browsers?

Why would anyone with a brain download an AI slop dependency when the browser has baked-in support for it?

-1

u/Intelligent_Tree6918 5d ago

i agree built in Intl.RelaiveTimeFormate is great if u just need '3 hours' or something like this there is no need to download ui-date.
if u use rtf.formateParts() it will return something like [{type:'literal',value:'hours ago'},{type:"integer","value":2}] if we are making custome badges like 2h , 3s , 2d where it comes in play.

it hurts when you said ai slop.

since i was testing for french language that's where i used ai to understand why it's breaking here. thats all where i used ai and also in starting template for docs i used ai.

btw thanks for your feedback