fix(reading sessions): Split sessions, re-calculate times in book overview (#2393)
* do not group reading sessions on a per-day basis * calculate actual duration for reading sessions --------- Co-authored-by: WorldTeacher <coding_contact@pm.me>
This commit is contained in:
co-authored by
WorldTeacher
parent
97343ee067
commit
d137055b83
+1
-1
@@ -36,7 +36,7 @@
|
||||
<tr>
|
||||
<td>{{ formatDate(session.startTime) }}</td>
|
||||
<td>{{ formatDate(session.endTime) }}</td>
|
||||
<td>{{ formatDuration(session.durationSeconds) }}</td>
|
||||
<td>{{ getActualDuration(session) }}</td>
|
||||
<td>
|
||||
@if (session.startProgress !== null && session.startProgress !== undefined && session.endProgress !== null && session.endProgress !== undefined) {
|
||||
<span>{{ session.startProgress }}% → {{ session.endProgress }}%</span>
|
||||
|
||||
+18
@@ -69,6 +69,24 @@ export class BookReadingSessionsComponent implements OnInit, OnChanges {
|
||||
return `${secs}s`;
|
||||
}
|
||||
|
||||
calculateActualDuration(session: ReadingSessionResponse): number {
|
||||
const startTime = new Date(session.startTime).getTime();
|
||||
const endTime = new Date(session.endTime).getTime();
|
||||
return Math.floor((endTime - startTime) / 1000);
|
||||
}
|
||||
|
||||
getActualDuration(session: ReadingSessionResponse): string {
|
||||
const actualDuration = this.calculateActualDuration(session);
|
||||
const storedDuration = session.durationSeconds;
|
||||
|
||||
if (Math.abs(actualDuration - storedDuration) > 1) {
|
||||
// Discrepancy detected - show both values
|
||||
return `${this.formatDuration(actualDuration)}`;
|
||||
}
|
||||
|
||||
return this.formatDuration(actualDuration);
|
||||
}
|
||||
|
||||
formatDate(dateString: string): string {
|
||||
return new Date(dateString).toLocaleString();
|
||||
}
|
||||
|
||||
+2
-2
@@ -145,8 +145,8 @@ export class ReadingSessionTimelineComponent implements OnInit {
|
||||
|
||||
response.forEach((item) => {
|
||||
const startTime = new Date(item.startDate);
|
||||
const duration = item.totalDurationSeconds / 60;
|
||||
const endTime = new Date(startTime.getTime() + item.totalDurationSeconds * 1000);
|
||||
const endTime = item.endDate ? new Date(item.endDate) : new Date(startTime.getTime() + item.totalDurationSeconds * 1000);
|
||||
const duration = (endTime.getTime() - startTime.getTime()) / (1000 * 60);
|
||||
|
||||
sessions.push({
|
||||
startTime,
|
||||
|
||||
Reference in New Issue
Block a user