mirror of
https://github.com/flarum/framework.git
synced 2025-05-29 03:21:57 +08:00
Replace Ember app with Mithril app
This commit is contained in:
40
js/lib/utils/human-time.js
Normal file
40
js/lib/utils/human-time.js
Normal file
@ -0,0 +1,40 @@
|
||||
moment.locale('en', {
|
||||
relativeTime : {
|
||||
future: "in %s",
|
||||
past: "%s ago",
|
||||
s: "seconds",
|
||||
m: "1m",
|
||||
mm: "%dm",
|
||||
h: "1h",
|
||||
hh: "%dh",
|
||||
d: "1d",
|
||||
dd: "%dd",
|
||||
M: "a month",
|
||||
MM: "%d months",
|
||||
y: "a year",
|
||||
yy: "%d years"
|
||||
}
|
||||
});
|
||||
|
||||
export default function humanTime(time) {
|
||||
var m = moment(time);
|
||||
|
||||
var minute = 6e4;
|
||||
var hour = 36e5;
|
||||
var day = 864e5;
|
||||
var ago = null;
|
||||
|
||||
var diff = m.diff(moment());
|
||||
|
||||
if (diff < -30 * day) {
|
||||
if (m.year() === moment().year()) {
|
||||
ago = m.format('D MMM');
|
||||
} else {
|
||||
ago = m.format('MMM \'YY');
|
||||
}
|
||||
} else {
|
||||
ago = m.fromNow();
|
||||
}
|
||||
|
||||
return ago;
|
||||
};
|
Reference in New Issue
Block a user