fix time duration
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import { ref, computed, watch } from "vue";
|
||||
import { invoke } from "@tauri-apps/api/core";
|
||||
import { DBEvent } from "../types";
|
||||
import { currentDate, getTagColor, getTagName, formatMinutes } from "./index";
|
||||
import { currentDate, getTagColor, getTagName, formatMinutes, parseISODate, toISODate } from "./index";
|
||||
|
||||
// Re-export for easier access in Dashboard component
|
||||
export { getTagColor, getTagName, formatMinutes };
|
||||
@@ -17,12 +17,17 @@ export const loadDashboardEvents = async () => {
|
||||
};
|
||||
|
||||
watch([dashboardRange, currentDate], () => {
|
||||
const end = new Date(currentDate.value);
|
||||
let start = new Date(currentDate.value);
|
||||
if (dashboardRange.value === '7days') start.setDate(end.getDate() - 6);
|
||||
else if (dashboardRange.value === '30days') start.setDate(end.getDate() - 29);
|
||||
dashboardStartDate.value = start.toLocaleDateString('sv');
|
||||
dashboardEndDate.value = end.toLocaleDateString('sv');
|
||||
const end = parseISODate(currentDate.value);
|
||||
let start = parseISODate(currentDate.value);
|
||||
|
||||
if (dashboardRange.value === '7days') {
|
||||
start.setDate(end.getDate() - 6);
|
||||
} else if (dashboardRange.value === '30days') {
|
||||
start.setDate(end.getDate() - 29);
|
||||
}
|
||||
|
||||
dashboardStartDate.value = toISODate(start);
|
||||
dashboardEndDate.value = toISODate(end);
|
||||
loadDashboardEvents();
|
||||
}, { immediate: true });
|
||||
|
||||
@@ -32,8 +37,7 @@ export const dashboardStats = computed(() => {
|
||||
const uniqueDays = new Set<string>();
|
||||
|
||||
dashboardEvents.value.forEach(ev => {
|
||||
let diff = ev.end_minute - ev.start_minute;
|
||||
if (diff < 0) diff += 1440;
|
||||
const diff = Math.max(0, ev.end_minute - ev.start_minute);
|
||||
totalMinutes += diff;
|
||||
uniqueDays.add(ev.date);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user