This repository has been archived on 2023-03-18. You can view files and clone it, but cannot push or open issues or pull requests.
osr-discourse-src/app/assets/javascripts/discourse/app/helpers/format-date.js
Martin Brennan 23b7b42acd
DEV: Bump eslint-config-discourse (#14868)
Changes for 4f7aba06c0

Also fixes all of the object-shorthand violations in our JS code.
2021-11-10 09:31:41 +10:00

35 lines
763 B
JavaScript

import { autoUpdatingRelativeAge } from "discourse/lib/formatter";
import { htmlSafe } from "@ember/template";
import { registerUnbound } from "discourse-common/lib/helpers";
/**
Display logic for dates. It is unbound in Ember but will use jQuery to
update the dates on a regular interval.
**/
registerUnbound("format-date", function (val, params) {
let leaveAgo,
format = "medium",
title = true;
if (params.leaveAgo) {
leaveAgo = params.leaveAgo === "true";
}
if (params.format) {
format = params.format;
}
if (params.noTitle) {
title = false;
}
if (val) {
let date = new Date(val);
return htmlSafe(
autoUpdatingRelativeAge(date, {
format,
title,
leaveAgo,
})
);
}
});