File size: 686 Bytes
f91a684
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
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]);
}