summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMaksim Sukharev <antreesy.web@gmail.com>2023-07-28 19:27:43 +0200
committerbackportbot-nextcloud[bot] <backportbot-nextcloud[bot]@users.noreply.github.com>2023-08-08 11:00:07 +0000
commitd758b92b8182cf51ea6facb756af7d9dac4b47c0 (patch)
tree8bfe15e6235d06eca85598f90ef7472f92aa9af7
parent2d1cf5e75908a3245594014fc3d90121b501690f (diff)
add util for call time formatting
Signed-off-by: Maksim Sukharev <antreesy.web@gmail.com>
-rw-r--r--src/components/TopBar/CallTime.vue33
-rw-r--r--src/utils/formattedTime.js26
2 files changed, 34 insertions, 25 deletions
diff --git a/src/components/TopBar/CallTime.vue b/src/components/TopBar/CallTime.vue
index d43fa740e..bc07fae29 100644
--- a/src/components/TopBar/CallTime.vue
+++ b/src/components/TopBar/CallTime.vue
@@ -39,7 +39,7 @@
:size="20"
fill-color="var(--color-loading-light)" />
</template>
- {{ formattedTime }}
+ {{ formattedTime(callTime) }}
</NcButton>
</template>
@@ -83,6 +83,7 @@ import NcPopover from '@nextcloud/vue/dist/Components/NcPopover.js'
import { CALL } from '../../constants.js'
import isInLobby from '../../mixins/isInLobby.js'
+import { formattedTime } from '../../utils/formattedTime.js'
export default {
name: 'CallTime',
@@ -131,30 +132,6 @@ export default {
return new Date(this.start * 1000)
},
- /**
- * Calculates the stopwatch string given the callTime (ms)
- *
- * @return {string} The formatted time
- */
- formattedTime() {
- if (!this.callTime) {
- return '-- : --'
- }
- let seconds = Math.floor((this.callTime / 1000) % 60)
- if (seconds < 10) {
- seconds = '0' + seconds
- }
- let minutes = Math.floor((this.callTime / (1000 * 60)) % 60)
- if (minutes < 10) {
- minutes = '0' + minutes
- }
- const hours = Math.floor((this.callTime / (1000 * 60 * 60)) % 24)
- if (hours === 0) {
- return minutes + ' : ' + seconds
- }
- return hours + ' : ' + minutes + ' : ' + seconds
- },
-
token() {
return this.$store.getters.getToken()
},
@@ -213,6 +190,12 @@ export default {
},
methods: {
+ /**
+ * Calculates the stopwatch string given the callTime (ms)
+ *
+ */
+ formattedTime,
+
stopRecording() {
this.$store.dispatch('stopCallRecording', {
token: this.token,
diff --git a/src/utils/formattedTime.js b/src/utils/formattedTime.js
new file mode 100644
index 000000000..9a528b10d
--- /dev/null
+++ b/src/utils/formattedTime.js
@@ -0,0 +1,26 @@
+/**
+ * Calculates the stopwatch string given the time (ms)
+ *
+ * @param {number} time the time in ms
+ * @param {boolean} [condensed=false] the format of string to show
+ * @return {string} The formatted time
+ */
+function formattedTime(time, condensed = false) {
+ if (!time) {
+ return condensed ? '--:--' : '-- : --'
+ }
+
+ const seconds = Math.floor((time / 1000) % 60)
+ const minutes = Math.floor((time / (1000 * 60)) % 60)
+ const hours = Math.floor((time / (1000 * 60 * 60)) % 24)
+
+ return [
+ hours,
+ minutes.toString().padStart(2, '0'),
+ seconds.toString().padStart(2, '0'),
+ ].filter(num => !!num).join(condensed ? ':' : ' : ')
+}
+
+export {
+ formattedTime,
+}