2018-09-12 17:14:45 +00:00
|
|
|
<template>
|
2019-07-17 09:33:59 +00:00
|
|
|
<div :aria-label="localeDate" class="date-marker-container tooltipped tooltipped-s">
|
2018-09-12 17:14:45 +00:00
|
|
|
<div class="date-marker">
|
2019-07-17 09:33:59 +00:00
|
|
|
<span :data-label="friendlyDate()" 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>
|