| function padDatePart(value: number) { |
| return String(value).padStart(2, '0'); |
| } |
|
|
| function normalizeCount(value: unknown) { |
| return typeof value === 'number' && Number.isFinite(value) ? value : 0; |
| } |
|
|
| export function getActivityDateKey(date: Date) { |
| return `${date.getFullYear()}-${padDatePart(date.getMonth() + 1)}-${padDatePart(date.getDate())}`; |
| } |
|
|
| export function getRecordedActivityCount(dailyActivity: Record<string, number>, date: Date) { |
| const localKey = getActivityDateKey(date); |
| if (localKey in dailyActivity) { |
| return normalizeCount(dailyActivity[localKey]); |
| } |
|
|
| const utcKey = date.toISOString().split('T')[0]; |
| return normalizeCount(dailyActivity[utcKey]); |
| } |
|
|