Follow-up from "Enable user setting for absolute dates"
The following discussion from !65570 (merged) should be addressed:
-
@peterhegman started a discussion: (+3 comments) thought:
timeago.js
exposes a few other methods,render
,cancel
,register
. https://github.com/hustcc/timeago.js/blob/master/src/index.tsI couldn't find any place in the codebase where we use those methods but with the current approach we may be setting ourselves up to call an undefined method by accident later down the road. What if we were to extend
timeago
and override theformat
method?Something like this may work:
let memoizedFormatter = null; function setupAbsoluteFormatter() { if (memoizedFormatter === null) { const formatter = createDateTimeFormat({ dateStyle: 'medium', timeStyle: 'short', }); memoizedFormatter = (date) => formatter.format(date instanceof Date ? date : new Date(date)); } return memoizedFormatter; } export const getTimeago = () => window.gon?.time_display_relative === false ? { ...timeago, format: setupAbsoluteFormatter() } : timeago;