2018-09-12 17:14:45 +00:00
|
|
|
<template>
|
|
|
|
<div
|
2018-09-12 18:00:03 +00:00
|
|
|
:aria-label="localeDate"
|
2018-09-12 17:14:45 +00:00
|
|
|
class="date-marker-container tooltipped tooltipped-s">
|
|
|
|
<div class="date-marker">
|
|
|
|
<span
|
2018-09-12 18:00:03 +00:00
|
|
|
:data-label="friendlyDate()"
|
2018-09-12 17:14:45 +00:00
|
|
|
class="date-marker-text" />
|
|
|
|
</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-12 18:09:43 +00:00
|
|
|
return moment.duration(moment().diff(moment(this.message.time))).asHours();
|
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>
|