2018-09-12 17:14:45 +00:00
|
|
|
<template>
|
|
|
|
<div
|
2018-09-12 18:00:03 +00:00
|
|
|
:aria-label="localeDate"
|
2019-02-25 05:38:13 +00:00
|
|
|
class="date-marker-container tooltipped tooltipped-s"
|
|
|
|
>
|
2018-09-12 17:14:45 +00:00
|
|
|
<div class="date-marker">
|
|
|
|
<span
|
2018-09-12 18:00:03 +00:00
|
|
|
:data-label="friendlyDate()"
|
2019-02-25 05:38:13 +00:00
|
|
|
class="date-marker-text"
|
|
|
|
/>
|
2018-09-12 17:14:45 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
const moment = require("moment");
|
|
|
|
|
|
|
|
export default {
|
|
|
|
name: "DateMarker",
|
|
|
|
props: {
|
|
|
|
message: Object,
|
|
|
|
},
|
2018-09-12 18:09:43 +00:00
|
|
|
computed: {
|
|
|
|
localeDate() {
|
|
|
|
return moment(this.message.time).format("D MMMM YYYY");
|
|
|
|
},
|
|
|
|
},
|
2018-09-12 17:14:45 +00:00
|
|
|
mounted() {
|
2018-09-12 18:00:03 +00:00
|
|
|
if (this.hoursPassed() < 48) {
|
2018-09-12 17:14:45 +00:00
|
|
|
this.$root.$on("daychange", this.dayChange);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
beforeDestroy() {
|
|
|
|
this.$root.$off("daychange", this.dayChange);
|
|
|
|
},
|
|
|
|
methods: {
|
2018-09-12 18:00:03 +00:00
|
|
|
hoursPassed() {
|
2018-09-20 07:50:00 +00:00
|
|
|
return (Date.now() - Date.parse(this.message.time)) / 3600000;
|
2018-09-12 18:00:03 +00:00
|
|
|
},
|
2018-09-12 17:14:45 +00:00
|
|
|
dayChange() {
|
|
|
|
this.$forceUpdate();
|
2018-09-12 18:00:03 +00:00
|
|
|
|
|
|
|
if (this.hoursPassed() >= 48) {
|
|
|
|
this.$root.$off("daychange", this.dayChange);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
friendlyDate() {
|
|
|
|
// See http://momentjs.com/docs/#/displaying/calendar-time/
|
|
|
|
return moment(this.message.time).calendar(null, {
|
|
|
|
sameDay: "[Today]",
|
|
|
|
lastDay: "[Yesterday]",
|
|
|
|
lastWeek: "D MMMM YYYY",
|
|
|
|
sameElse: "D MMMM YYYY",
|
|
|
|
});
|
2018-09-12 17:14:45 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
</script>
|