better time formatting in status section

practiced-songs
Matthew Huntington 1 year ago
parent bd02cc79c7
commit 66cc5fbdc6

@ -1,28 +1,28 @@
<script lang="ts"> <script lang="ts">
import axios from 'axios'; import axios from 'axios';
import { getHours, getMinutes, createTimeObj, getAccumulatedSeconds, formatSeconds } from '../libs/time.js'
export default { export default {
data() { data() {
return { return {
time_left:0, seconds_left_to_practice_today:0,
mins_practiced_today:0, seconds_practiced_today:0,
to_get_ahead:0 seconds_left_to_get_ahead:0
} }
}, },
methods: { methods: {
setTimes(response){ setTimes(response){
this.time_left= response.data.time_left; this.seconds_left_to_practice_today = response.data.seconds_left_to_practice_today
this.mins_practiced_today = response.data.mins_practiced_today; this.seconds_practiced_today = response.data.seconds_practiced
this.seconds_left_to_get_ahead = response.data.seconds_left_to_get_ahead
const today = new Date()
this.to_get_ahead = this.time_left + (today.getMonth()+1)*150 + today.getDate()*5
}, },
refresh(){ refresh(){
axios.get(import.meta.env.VITE_PRACTICE_TRACKER_API_URL+'mins-left-to-practice-today').then(this.setTimes) axios.get(import.meta.env.VITE_PRACTICE_TRACKER_API_URL+'status').then(this.setTimes)
} },
formatSeconds
}, },
mounted() { mounted() {
axios.get(import.meta.env.VITE_PRACTICE_TRACKER_API_URL+'mins-left-to-practice-today').then(this.setTimes) axios.get(import.meta.env.VITE_PRACTICE_TRACKER_API_URL+'status').then(this.setTimes)
} }
} }
</script> </script>
@ -30,11 +30,11 @@
<template> <template>
<h2 @click="refresh">Time Summary</h2> <h2 @click="refresh">Time Summary</h2>
<h3>Mins Left to Practice Today</h3> <h3>Mins Left to Practice Today</h3>
{{time_left.toFixed(4)}} {{formatSeconds(seconds_left_to_practice_today,true)}}
<h3>To Get Ahead</h3> <h3>To Get Ahead</h3>
{{to_get_ahead.toFixed(4)}} {{formatSeconds(seconds_left_to_get_ahead,true)}}
<h3>Mins Practiced Today</h3> <h3>Mins Practiced Today</h3>
{{mins_practiced_today.toFixed(4)}} {{formatSeconds(seconds_practiced_today,true)}}
</template> </template>
<style scoped> <style scoped>

@ -1,30 +1,6 @@
<script lang="ts"> <script lang="ts">
import axios from 'axios'; import axios from 'axios';
import { getHours, getMinutes, createTimeObj, getAccumulatedSeconds, formatSeconds } from '../libs/time.js'
const getHours = (seconds) => {
return Math.floor( seconds / 60 / 60 );
}
const getMinutes = (seconds) => {
return Math.floor( seconds / 60 );
}
const createTimeObj = (seconds) => {
const hours = getHours(seconds)
let remainingSeconds = seconds - hours * 60 * 60
const minutes = getMinutes(remainingSeconds)
remainingSeconds -= minutes * 60
return { hours, minutes, seconds: remainingSeconds }
}
const getAccumulatedSeconds = (newerTime, olderTime) => {
return Math.floor((newerTime-olderTime)/1000);
}
const formatSeconds = (total) => {
const timeObj = createTimeObj(total)
return `${timeObj.hours*60 + timeObj.minutes}:${timeObj.seconds.toString().padStart(2,'0')}`;
}
export default { export default {
props: ['currentWorkingCategoryID'], props: ['currentWorkingCategoryID'],
@ -48,9 +24,7 @@
} }
}, },
methods: { methods: {
formatTime(seconds){ formatSeconds,
return formatSeconds(seconds)
},
submit(event){ submit(event){
event.preventDefault(); event.preventDefault();
const reqBody = { const reqBody = {
@ -188,7 +162,7 @@
<h2>Timer</h2> <h2>Timer</h2>
<div :class="{running:running, micThresholdExceeded:micThresholdExceeded}"> <div :class="{running:running, micThresholdExceeded:micThresholdExceeded}">
<em> <em>
{{formatTime(totalSeconds)}} {{formatSeconds(totalSeconds, true)}}
</em> </em>
Mic Threshold (current level: {{Math.round(micLevel)}}): Mic Threshold (current level: {{Math.round(micLevel)}}):
<input type="number" @change="activateMic" v-model="micThreshold"/> <input type="number" @change="activateMic" v-model="micThreshold"/>

@ -0,0 +1,30 @@
const getHours = (seconds) => {
return Math.floor( seconds / 60 / 60 );
}
const getMinutes = (seconds) => {
return Math.floor( seconds / 60 );
}
const createTimeObj = (seconds) => {
const hours = getHours(seconds)
let remainingSeconds = seconds - hours * 60 * 60
const minutes = getMinutes(remainingSeconds)
remainingSeconds -= minutes * 60
return { hours, minutes, seconds: remainingSeconds }
}
const getAccumulatedSeconds = (newerTime, olderTime) => {
return Math.floor((newerTime-olderTime)/1000);
}
const formatSeconds = (total, includeHours = false) => {
const timeObj = createTimeObj(total)
if(includeHours) {
return `${timeObj.hours}:${timeObj.minutes.toString().padStart(2,'0')}:${timeObj.seconds.toString().padStart(2,'0')}`;
} else {
return `${timeObj.hours*60 + timeObj.minutes}:${timeObj.seconds.toString().padStart(2,'0')}`;
}
}
export { getHours, getMinutes, createTimeObj, getAccumulatedSeconds, formatSeconds }
Loading…
Cancel
Save