Skip to content

Instantly share code, notes, and snippets.

@acidjazz
Created October 22, 2019 23:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save acidjazz/8d51f85279b14c4a561eb57be79f0e8c to your computer and use it in GitHub Desktop.
Save acidjazz/8d51f85279b14c4a561eb57be79f0e8c to your computer and use it in GitHub Desktop.
<template lang="pug">
time.tooltip(
:datetime="value",
:data-tooltip="value.format('dddd, MMM Do, `YY @ hh:mm:ss a')",
) {{ formatted(format) }}
</template>
<script>
export default {
props: {
value: {
type: Object,
required: true,
},
type: {
type: String,
required: false,
default: 'fromNow',
},
format: {
type: [String,Boolean],
required: false,
default: false,
},
},
methods: {
formatted(type) {
if (this.format)
return this.value.format(this.format)
if (this.type === 'long')
return this.value.format('dddd, MMM Do, `YY @ hh:mm:ss a')
if (this.type === 'human')
return this.value.format('ddd, MMM Do, h:mm a')
if (this.type === 'time')
return this.value.format('h:mm a')
if (this.type === 'fromNow') {
return this.value.fromNow()
}
}
},
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment