parsley/app/javascript/components/AppDateTime.vue

63 lines
1.2 KiB
Vue
Raw Permalink Normal View History

2018-04-03 18:31:20 -05:00
<template>
2018-04-14 15:04:08 -05:00
<span>
<input v-if="useInput" class="text" type="text" readonly :value="friendlyString" />
<span v-else :title="fullString">{{ friendlyString }}</span>
</span>
2018-04-03 18:31:20 -05:00
</template>
<script>
2018-04-13 23:32:34 -05:00
import DateTimeUtils from "../lib/DateTimeUtils";
2018-04-03 18:31:20 -05:00
export default {
props: {
dateTime: {
required: true,
type: [Date, String]
},
showDate: {
required: false,
type: Boolean,
default: true
},
showTime: {
required: false,
type: Boolean,
default: true
2018-04-14 15:04:08 -05:00
},
useInput: {
required: false,
type: Boolean,
default: false
2018-04-03 18:31:20 -05:00
}
},
computed: {
dateObj() {
2018-04-13 23:32:34 -05:00
return DateTimeUtils.toDate(this.dateTime);
2018-04-03 18:31:20 -05:00
},
friendlyString() {
const parts = [];
if (this.showDate) {
2018-04-13 23:32:34 -05:00
parts.push(DateTimeUtils.formatDate(this.dateObj));
2018-04-03 18:31:20 -05:00
}
if (this.showTime) {
2018-04-13 23:32:34 -05:00
parts.push(DateTimeUtils.formatTime(this.dateObj, true));
2018-04-03 18:31:20 -05:00
}
return parts.join(" ");
},
fullString() {
2018-04-13 23:32:34 -05:00
return DateTimeUtils.formatTimestamp(this.dateObj);
2018-04-03 18:31:20 -05:00
}
}
}
</script>
<style lang="scss" scoped>
</style>