This commit is contained in:
dohsimpson
2025-01-01 23:27:20 -05:00
parent 11ea0ff89e
commit 7afe81ddd5
2 changed files with 10 additions and 5 deletions

View File

@@ -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 (
<div className="p-4 bg-white rounded-lg shadow">

View File

@@ -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<Habit[]>([])
@@ -21,7 +21,7 @@ export function useHabits() {
}
const addHabit = async (habit: Omit<Habit, 'id'>) => {
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)