All three widgets rely at the moment on Icinga Web:
To get rid of \Icinga\Date\DateFormatter::formatDateTime() is relatively straightforward since <time> elements mandate a specific format that can be hard-coded.
\Icinga\Date\DateFormatter::timeAgo() (and all its counterparts) on the other hand may be simply copied over to the respective widget.
Though, all three of them are based on \Icinga\Date\DateFormatter::diff() so why not introducing a new widget: ipl\Web\Widget\Time. The other three extend it and can access its protected method ipl\Web\Widget\Time::diff(). (Which is a modernized copy of \Icinga\Date\DateFormatter::diff(), also consider using \DateTime::diff())
Note that I don't think ipl\Web\Widget\Time should be abstract, it should rather provide a reasonable default content. (e.g. not declare the datetime attribute and instead rendering the datetime in the content)
One might also think about ipl\Web\Widget\Time::relative(\DateTime): static that automatically chooses TimeUntil or TimeAgo depending on the input.
For the client side, we should provide a default Icinga Web behavior called RelativeTime that provides an implementation very similar to https://github.com/Icinga/icingaweb2/blob/70f29827f921f24b2afc0556c4800dfa55a2d0c1/public/js/icinga/ui.js#L484 but using ECMAScript 2015 features only. (No jQuery) Instead of reacting on CSS classes, it should also react on data attributes.
Talking of modernized JS, don't forget that there's Intl.RelativeTimeFormat which might serve as alternative to the server side localization.
All three widgets rely at the moment on Icinga Web:
\Icinga\Date\DateFormatterto format datetime valuesTo get rid of
\Icinga\Date\DateFormatter::formatDateTime()is relatively straightforward since<time>elements mandate a specific format that can be hard-coded.\Icinga\Date\DateFormatter::timeAgo()(and all its counterparts) on the other hand may be simply copied over to the respective widget.Though, all three of them are based on
\Icinga\Date\DateFormatter::diff()so why not introducing a new widget:ipl\Web\Widget\Time. The other three extend it and can access its protected methodipl\Web\Widget\Time::diff(). (Which is a modernized copy of\Icinga\Date\DateFormatter::diff(), also consider using\DateTime::diff())Note that I don't think
ipl\Web\Widget\Timeshould be abstract, it should rather provide a reasonable default content. (e.g. not declare thedatetimeattribute and instead rendering the datetime in the content)One might also think about
ipl\Web\Widget\Time::relative(\DateTime): staticthat automatically choosesTimeUntilorTimeAgodepending on the input.For the client side, we should provide a default Icinga Web behavior called
RelativeTimethat provides an implementation very similar to https://github.com/Icinga/icingaweb2/blob/70f29827f921f24b2afc0556c4800dfa55a2d0c1/public/js/icinga/ui.js#L484 but using ECMAScript 2015 features only. (No jQuery) Instead of reacting on CSS classes, it should also react on data attributes.Talking of modernized JS, don't forget that there's
Intl.RelativeTimeFormatwhich might serve as alternative to the server side localization.