Has anyone used or knows how to use the MomentJs library (https://momentjs.com/) on WeWeb?
I advise not to use moment, as this is a deprecated library.
What is your usecase?
You can use
- Our date plugin
- Native browser date function (a lot of them are available now)
- An other more modern and light library, like Date-fns
I tried to use the plugin, but I can’t bring the time in hours/minutes/seconds between two dates and also display something like “3 hours ago”"
In the case of Date-Fns, how would you use it?
Depending on your usage:
- if you just need a text which will display “6 months ago”, custom component is the way to go
- If you want formula to use in different places, custom plugin is the way to go (but you need to contact us for this, as it is not available for everyone at the moment)
- You can always hack by loading the script yourself (through the CDN version), but you may have difficulty to handle this properly at first load and inside the editor
Please don’t hesitate to make a feature request on feedback.weweb.io so we can put it in the backlog and improve the date plugin according to your needs. We could add a formula in the date plugin to achieve the “3 hours ago” thing for example!
This would be perfect, as it is very common in many solutions. I’m sure implementing this feature will benefit everyone.
In luxon, the toRelative method gives you the kind of notation you are looking for: DateTime | Luxon