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/helpers/format-date.js.es6
2018-06-15 17:03:24 +02:00

34 lines
759 B
JavaScript

import { registerUnbound } from "discourse-common/lib/helpers";
import { autoUpdatingRelativeAge } from "discourse/lib/formatter";
/**
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) {
var 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) {
var date = new Date(val);
return new Handlebars.SafeString(
autoUpdatingRelativeAge(date, {
format: format,
title: title,
leaveAgo: leaveAgo
})
);
}
});