Enable overriding the current time

This commit is contained in:
Matt Isenhower
2022-09-20 19:59:11 -07:00
parent 5d6b0a362a
commit 3a411319d9
2 changed files with 13 additions and 3 deletions

View File

@@ -32,7 +32,8 @@
</template>
<script setup>
import { onMounted, onUnmounted } from 'vue';
import { onMounted, onUnmounted, watchEffect } from 'vue';
import { useRoute } from 'vue-router';
import { useDataStore } from '../stores/data';
import { useTimeStore } from '../stores/time';
@@ -42,12 +43,18 @@ const props = defineProps({
},
})
const route = useRoute();
const time = useTimeStore();
const data = useDataStore();
onMounted(() => time.startUpdatingNow());
onMounted(() => data.updateAll());
onUnmounted(() => time.stopUpdatingNow());
watchEffect(() => {
if (route.query.time) {
time.setNow(route.query.time);
}
});
function formatDateTime(date) {
date = new Date(date);

View File

@@ -14,6 +14,9 @@ export const useTimeStore = defineStore('time', {
now: now(),
}),
actions: {
setNow(value) {
this.now = value;
},
updateNow() {
this.now = now();
},