2018-12-13 13:39:08 +05:30
|
|
|
<script>
|
|
|
|
import { calculateRemainingMilliseconds, formatTime } from '~/lib/utils/datetime_utility';
|
2019-02-15 15:39:39 +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,
|
|
|
|
},
|
2019-12-04 20:38:33 +05:30
|
|
|
|
2018-12-13 13:39:08 +05:30
|
|
|
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-15 15:39:39 +05:30
|
|
|
<time v-gl-tooltip :datetime="endDateString" :title="endDateString"> {{ remainingTime }} </time>
|
2018-12-13 13:39:08 +05:30
|
|
|
</template>
|