debian-mirror-gitlab/app/assets/javascripts/vue_shared/components/gl_countdown.vue

54 lines
1.1 KiB
Vue
Raw Normal View History

2018-12-13 13:39:08 +05:30
<script>
import { calculateRemainingMilliseconds, formatTime } from '~/lib/utils/datetime_utility';
2019-01-03 12:48:30 +05:30
import { GlTooltipDirective } from '@gitlab-org/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-01-03 12:48:30 +05:30
<time
v-gl-tooltip
:datetime="endDateString"
:title="endDateString"
>
{{ remainingTime }}
</time>
2018-12-13 13:39:08 +05:30
</template>