Created
October 22, 2019 23:46
-
-
Save acidjazz/8d51f85279b14c4a561eb57be79f0e8c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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