2018-12-13 13:39:08 +05:30
|
|
|
<script>
|
|
|
|
import { calculateRemainingMilliseconds, formatTime } from '~/lib/utils/datetime_utility';
|
2019-02-13 22:33:31 +05:30
|
|
|
import { GlTooltipDirective } from '@gitlab/ui';
|
2018-12-13 13:39:08 +05:30
|
|
|
|
|
|
|
/**
|
|
|
|
* Counts down to a given end date.
|
|
|
|
*/
|
|
|
|
export default {
|
|
|
|
directives: {
|
|
|
|
GlTooltip: GlTooltipDirective,
|
|
|
|
},
|
|
|
|
props: {
|
|
|
|
endDateString: {
|
|
|
|
type: String,
|
|
|
|
required: true,
|
|
|
|
validator(value) {
|
|
|
|
return !Number.isNaN(new Date(value).getTime());
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
remainingTime: formatTime(0),
|
|
|
|
countdownUpdateIntervalId: null,
|
|
|
|
};
|
|
|
|
},
|
|
|
|
|
|
|
|
mounted() {
|
|
|
|
const updateRemainingTime = () => {
|
|
|
|
const remainingMilliseconds = calculateRemainingMilliseconds(this.endDateString);
|
|
|
|
this.remainingTime = formatTime(remainingMilliseconds);
|
|
|
|
};
|
|
|
|
|
|
|
|
updateRemainingTime();
|
|
|
|
this.countdownUpdateIntervalId = window.setInterval(updateRemainingTime, 1000);
|
|
|
|
},
|
|
|
|
|
|
|
|
beforeDestroy() {
|
|
|
|
window.clearInterval(this.countdownUpdateIntervalId);
|
|
|
|
},
|
|
|
|
};
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<template>
|
2019-02-13 22:33:31 +05:30
|
|
|
<time v-gl-tooltip :datetime="endDateString" :title="endDateString"> {{ remainingTime }} </time>
|
2018-12-13 13:39:08 +05:30
|
|
|
</template>
|