Fix timeline

This commit is contained in:
Nicolas Mowen 2024-02-02 15:12:59 -07:00
parent ccfa663b14
commit d1e72154c4
3 changed files with 11 additions and 6 deletions

View File

@ -284,8 +284,13 @@ export function getRangeForTimestamp(timestamp: number) {
date.setHours(date.getHours() + 1); date.setHours(date.getHours() + 1);
// ensure not to go past current time // ensure not to go past current time
const end = Math.min(new Date().getTime() / 1000, date.getTime() / 1000); return { start, end: endOfHourOrCurrentTime(date.getTime() / 1000) };
return { start, end }; }
export function endOfHourOrCurrentTime(timestamp: number) {
const now = new Date();
now.setMilliseconds(0);
return Math.min(timestamp, now.getTime() / 1000);
} }
export function isCurrentHour(timestamp: number) { export function isCurrentHour(timestamp: number) {

View File

@ -1,3 +1,5 @@
import { endOfHourOrCurrentTime } from "./dateUtil";
// group history cards by 120 seconds of activity // group history cards by 120 seconds of activity
const GROUP_SECONDS = 120; const GROUP_SECONDS = 120;
@ -169,7 +171,7 @@ export function getTimelineHoursForDay(
break; break;
} }
end = startDay.getTime() / 1000; end = endOfHourOrCurrentTime(startDay.getTime() / 1000);
const hour = Object.values(day).find((cards) => { const hour = Object.values(day).find((cards) => {
const card = Object.values(cards)[0]; const card = Object.values(cards)[0];
if (card == undefined || card.time < start || card.time > end) { if (card == undefined || card.time < start || card.time > end) {

View File

@ -180,9 +180,7 @@ export default function DesktopTimelineView({
timeline.range.start == selectedPlayback.range.start; timeline.range.start == selectedPlayback.range.start;
const graphData = timelineGraphData[timeline.range.start]; const graphData = timelineGraphData[timeline.range.start];
const start = new Date(timeline.range.start * 1000); const start = new Date(timeline.range.start * 1000);
const end = new Date( const end = new Date(timeline.range.end * 1000);
Math.min(timeline.range.end * 1000, new Date().getTime())
);
return ( return (
<div <div