Tooling around with docs. Show timestamps as relative ('3 hours ago').

git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@3810 ed5197a5-7fde-0310-b194-c3ffbd925b24
This commit is contained in:
2022-01-30 21:44:27 +00:00
parent ea92fbdcea
commit bf7d5c34f6
6 changed files with 54 additions and 12 deletions

View File

@ -16,7 +16,27 @@ Vue.component('tf-message', {
} catch {
return this.message.content;
}
}
},
timestamp_relative: function() {
var units = [
{value: 1, name: 'milliseconds'},
{value: 1000, name: 'seconds'},
{value: 1000 * 60, name: 'minutes'},
{value: 1000 * 60 * 60, name: 'hours'},
{value: 1000 * 60 * 60 * 24, name: 'days'},
{value: 1000 * 60 * 60 * 24 * 7, name: 'weeks'},
{value: 1000 * 60 * 60 * 24 * 30, name: 'months'},
{value: 1000 * 60 * 60 * 24 * 365, name: 'years'},
];
var v = new Date().valueOf() - this.message.timestamp;
var result = null;
for (let unit of units) {
if (v >= unit.value) {
result = Math.round(v / unit.value) + ' ' + unit.name + ' ago';
}
}
return result;
},
},
methods: {
markdown: markdown,
@ -79,8 +99,11 @@ Vue.component('tf-message', {
</h3>
<template v-if="message.author">
<div style="font-size: x-small">
{{new Date(message.timestamp)}}
<md-tooltip>{{message.id}}</md-tooltip>
{{timestamp_relative}}
<md-tooltip style="height: auto">
<div>{{new Date(message.timestamp)}}</div>
<div>{{message.id}}</div>
</md-tooltip>
</div>
<div class="md-toolbar-section-end">
<md-menu>