From 2b3e2039b8e95a0a1b8233c2b365907ec68264e5 Mon Sep 17 00:00:00 2001 From: vabene1111 Date: Tue, 26 Mar 2024 07:52:43 +0100 Subject: [PATCH] playing with the timer --- vue3/src/components/display/Step.vue | 40 ++++++++++++++++++++++------ 1 file changed, 32 insertions(+), 8 deletions(-) diff --git a/vue3/src/components/display/Step.vue b/vue3/src/components/display/Step.vue index 84581dfe6..ce0b26535 100644 --- a/vue3/src/components/display/Step.vue +++ b/vue3/src/components/display/Step.vue @@ -5,22 +5,34 @@ {{ step.name }} - {{ step.time }} + {{ step.time }} - + + + + + {{ remaining_time }} Finished at {{ finished_at }} + - + @@ -44,13 +56,15 @@ export default defineComponent({ } return '' }, + timerProgress: function () { + if (this.timer_end != null && this.timer_start != null && this.step.time != undefined) { + return (Interval.fromDateTimes(this.timer_start, this.time_now).length('seconds') / (this.step.time * 60)) * 100 + } + return 0 + }, remaining_time: function () { if (this.timer_end != null) { - if (Interval.fromDateTimes(this.time_now, this.timer_end).length() > 0){ - return Duration.fromMillis(Interval.fromDateTimes(this.time_now, this.timer_end).length()).toFormat('hh:mm:ss') - } else { - return '00:00:00' - } + return Duration.fromMillis(Interval.fromDateTimes(this.time_now, this.timer_end).length()).toFormat('hh:mm:ss') } return '' }, @@ -75,6 +89,7 @@ export default defineComponent({ data() { return { timer_end: null as null | DateTime, + timer_start: null as null | DateTime, time_now: DateTime.now(), } }, @@ -85,7 +100,16 @@ export default defineComponent({ }, methods: { startTimer(minutes: number) { + this.timer_start = DateTime.now() this.timer_end = DateTime.now().plus({minutes: minutes}) + }, + subTimer(){ + if (this.timer_end != null){ + this.timer_end = this.timer_end.minus({minutes: 1}) + } + }, + addTimer(){ + this.timer_end?.plus({minutes: 1}) } } })