summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/pipelines/components/time_ago.vue
blob: 79dbdca40107a055a0caaa29a1dd1de5f4372a5a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
<script>
  import iconTimerSvg from 'icons/_icon_timer.svg';
  import '../../lib/utils/datetime_utility';
  import tooltip from '../../vue_shared/directives/tooltip';
  import timeagoMixin from '../../vue_shared/mixins/timeago';

  export default {
    directives: {
      tooltip,
    },
    mixins: [
      timeagoMixin,
    ],
    props: {
      finishedTime: {
        type: String,
        required: true,
      },
      duration: {
        type: Number,
        required: true,
      },
    },
    data() {
      return {
        iconTimerSvg,
      };
    },
    computed: {
      hasDuration() {
        return this.duration > 0;
      },
      hasFinishedTime() {
        return this.finishedTime !== '';
      },
      durationFormated() {
        const date = new Date(this.duration * 1000);

        let hh = date.getUTCHours();
        let mm = date.getUTCMinutes();
        let ss = date.getSeconds();

        // left pad
        if (hh < 10) {
          hh = `0${hh}`;
        }
        if (mm < 10) {
          mm = `0${mm}`;
        }
        if (ss < 10) {
          ss = `0${ss}`;
        }

        return `${hh}:${mm}:${ss}`;
      },
    },
  };
</script>
<template>
  <div class="table-section section-15 pipelines-time-ago">
    <div
      class="table-mobile-header"
      role="rowheader"
    >
      Duration
    </div>
    <div class="table-mobile-content">
      <p
        class="duration"
        v-if="hasDuration"
      >
        <span v-html="iconTimerSvg">
        </span>
        {{ durationFormated }}
      </p>

      <p
        class="finished-at d-none d-sm-none d-md-block"
        v-if="hasFinishedTime"
      >

        <i
          class="fa fa-calendar"
          aria-hidden="true"
        >
        </i>

        <time
          v-tooltip
          data-placement="top"
          data-container="body"
          :title="tooltipTitle(finishedTime)">
          {{ timeFormated(finishedTime) }}
        </time>
      </p>
    </div>
  </div>
</template>