Skip to content

Commit ccbb98f

Browse files
committed
fix: fix incorrect isFuture calculation in history section
1 parent 3fc125b commit ccbb98f

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

src/app/history/history-log-2.tsx

+4-4
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ import {
1212
endOfWeek,
1313
eachDayOfInterval,
1414
isWithinInterval,
15-
startOfToday,
1615
isSameYear,
16+
endOfToday,
1717
} from 'date-fns'
1818
import { MonthlyLogDTO } from './log2'
1919
import clsx from 'clsx'
@@ -29,7 +29,7 @@ function isInThisYear(date: Date) {
2929
}
3030

3131
function isInTheFuture(date: Date) {
32-
return isAfter(date, startOfToday())
32+
return isAfter(date, endOfToday())
3333
}
3434

3535
export function HistoryLogV2({ monthLogs }: { monthLogs: MonthlyLogDTO[] }) {
@@ -62,8 +62,8 @@ export function HistoryLogV2({ monthLogs }: { monthLogs: MonthlyLogDTO[] }) {
6262
{isThisMonth(month)
6363
? 'This Month'
6464
: isInThisYear(month)
65-
? format(month, 'MMMM')
66-
: format(month, 'MMMM, yyyy')}
65+
? format(month, 'MMMM')
66+
: format(month, 'MMMM, yyyy')}
6767
</h3>
6868
<p>Verses: {monthLog.numberOfVersesTyped}</p>
6969
</div>

src/app/history/log2.tsx

+5-4
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,10 @@ export function getLog2(
4242
for (const typingSession of typingSessions) {
4343
if (typingSession.typedVerses.length === 0) continue
4444
const serverUTCOffset = new Date().getTimezoneOffset()
45+
4546
const clientTimezoneCreatedAt = new Date(
4647
typingSession.createdAt.getTime() +
47-
(clientTimezoneOffset - serverUTCOffset) * 60 * 1000,
48+
(serverUTCOffset - clientTimezoneOffset) * 60 * 1000,
4849
)
4950
const monthString = format(clientTimezoneCreatedAt, 'yyyy-MM')
5051
const dayString = format(clientTimezoneCreatedAt, 'dd')
@@ -59,7 +60,7 @@ export function getLog2(
5960
[dayString]: {
6061
typedVerses: typingSession.typedVerses,
6162
numberOfVersesTyped: typingSession.typedVerses.length,
62-
createdAt: clientTimezoneCreatedAt,
63+
createdAt: typingSession.createdAt,
6364
},
6465
},
6566
}
@@ -69,7 +70,7 @@ export function getLog2(
6970
currentMonthLog.days[dayString] = {
7071
typedVerses: typingSession.typedVerses,
7172
numberOfVersesTyped: typingSession.typedVerses.length,
72-
createdAt: clientTimezoneCreatedAt,
73+
createdAt: typingSession.createdAt,
7374
}
7475
} else {
7576
currentMonthLog.numberOfVersesTyped +=
@@ -82,7 +83,7 @@ export function getLog2(
8283
numberOfVersesTyped:
8384
currentDayLog.numberOfVersesTyped +
8485
typingSession.typedVerses.length,
85-
createdAt: clientTimezoneCreatedAt,
86+
createdAt: typingSession.createdAt,
8687
}
8788
}
8889
}

0 commit comments

Comments
 (0)