From 7afe81ddd5344e83d70606c84e1f4da4d7fce990 Mon Sep 17 00:00:00 2001 From: dohsimpson Date: Wed, 1 Jan 2025 23:27:20 -0500 Subject: [PATCH] fix --- components/HabitHeatmap.tsx | 9 +++++++-- hooks/useHabits.tsx | 6 +++--- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/components/HabitHeatmap.tsx b/components/HabitHeatmap.tsx index 9527b1b..d2f4b81 100644 --- a/components/HabitHeatmap.tsx +++ b/components/HabitHeatmap.tsx @@ -2,6 +2,8 @@ import HeatMap from '@uiw/react-heat-map' import { Habit } from '@/lib/types' +import { getDateInTimezone } from '@/lib/utils' +import { useSettings } from '@/hooks/useSettings' interface HabitHeatmapProps { habits: Habit[] @@ -24,9 +26,12 @@ export default function HabitHeatmap({ habits }: HabitHeatmapProps) { count })) + const { settings } = useSettings() + // Get start date (30 days ago) - const startDate = new Date() - startDate.setDate(startDate.getDate() - 30) + const now = getDateInTimezone(new Date(), settings.system.timezone) + const startDate = now + startDate.setDate(now.getDate() - 30) return (
diff --git a/hooks/useHabits.tsx b/hooks/useHabits.tsx index 1994902..9d5f8bb 100644 --- a/hooks/useHabits.tsx +++ b/hooks/useHabits.tsx @@ -5,7 +5,7 @@ import { toast } from '@/hooks/use-toast' import { ToastAction } from '@/components/ui/toast' import { Undo2 } from 'lucide-react' import { Habit } from '@/lib/types' -import { getTodayInTimezone } from '@/lib/utils' +import { getDateInTimezone, getTodayInTimezone } from '@/lib/utils' export function useHabits() { const [habits, setHabits] = useState([]) @@ -21,7 +21,7 @@ export function useHabits() { } const addHabit = async (habit: Omit) => { - const newHabit = { ...habit, id: Date.now().toString() } + const newHabit = { ...habit, id: getDateInTimezone(new Date(), settings.system.timezone).getTime().toString() } const newHabits = [...habits, newHabit] setHabits(newHabits) await saveHabitsData({ habits: newHabits }) @@ -74,7 +74,7 @@ export function useHabits() { } const undoComplete = async (habit: Habit) => { - const today = new Date().toISOString().split('T')[0] + const today = getTodayInTimezone(settings.system.timezone) const updatedHabit = { ...habit, completions: habit.completions.filter(date => date !== today)