summaryrefslogtreecommitdiff
path: root/src/client/app/common/views/components/timer.vue
diff options
context:
space:
mode:
authorsyuilo <syuilotan@yahoo.co.jp>2018-03-29 20:32:18 +0900
committersyuilo <syuilotan@yahoo.co.jp>2018-03-29 20:32:18 +0900
commitcf33e483f7e6f40e8cbbbc0118a7df70bdaf651f (patch)
tree318279530d3392ee40d91968477fc0e78d5cf0f7 /src/client/app/common/views/components/timer.vue
parentUpdate .travis.yml (diff)
downloadmisskey-cf33e483f7e6f40e8cbbbc0118a7df70bdaf651f.tar.gz
misskey-cf33e483f7e6f40e8cbbbc0118a7df70bdaf651f.tar.bz2
misskey-cf33e483f7e6f40e8cbbbc0118a7df70bdaf651f.zip
整理した
Diffstat (limited to 'src/client/app/common/views/components/timer.vue')
-rw-r--r--src/client/app/common/views/components/timer.vue49
1 files changed, 49 insertions, 0 deletions
diff --git a/src/client/app/common/views/components/timer.vue b/src/client/app/common/views/components/timer.vue
new file mode 100644
index 0000000000..a3c4f01b77
--- /dev/null
+++ b/src/client/app/common/views/components/timer.vue
@@ -0,0 +1,49 @@
+<template>
+<time class="mk-time">
+ {{ hh }}:{{ mm }}:{{ ss }}
+</time>
+</template>
+
+<script lang="ts">
+import Vue from 'vue';
+
+export default Vue.extend({
+ props: {
+ time: {
+ type: [Date, String],
+ required: true
+ }
+ },
+ data() {
+ return {
+ tickId: null,
+ hh: null,
+ mm: null,
+ ss: null
+ };
+ },
+ computed: {
+ _time(): Date {
+ return typeof this.time == 'string' ? new Date(this.time) : this.time;
+ }
+ },
+ created() {
+ this.tick();
+ this.tickId = setInterval(this.tick, 1000);
+ },
+ destroyed() {
+ clearInterval(this.tickId);
+ },
+ methods: {
+ tick() {
+ const now = new Date().getTime();
+ const start = this._time.getTime();
+ const ago = Math.floor((now - start) / 1000);
+
+ this.hh = Math.floor(ago / (60 * 60)).toString().padStart(2, '0');
+ this.mm = Math.floor(ago / 60).toString().padStart(2, '0');
+ this.ss = (ago % 60).toString().padStart(2, '0');
+ }
+ }
+});
+</script>