Skip to content
This repository has been archived by the owner on Feb 24, 2023. It is now read-only.

Realtime graph issue #94

Merged
merged 4 commits into from
May 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions ui/src/hooks/chart/useChartPeriod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import {
addMinutesUTC,
addMonthsUTC,
differenceDaysUTC,
differenceHoursUTC,
differenceMinutesUTC,
displayDayDetails,
displayFullMonth,
displayHourDetails,
Expand All @@ -19,6 +21,7 @@ import {
stringToUTCTimestamp,
subDaysUTC,
subMonthsUTC,
timestampDisplay,
UTCNow,
UTCTimestamp,
} from '../../utils/DateTimeUtils';
Expand Down Expand Up @@ -137,19 +140,19 @@ export const datesFromChartPeriod = (
): UTCTimestamp[] => {
switch (period) {
case 'day':
return Array(24)
return Array(differenceHoursUTC(to, from) + 1)
.fill(from)
.map((_, i) => addHoursUTC(_, i));
case 'realtime':
return Array(31)
return Array(differenceMinutesUTC(to, from) + 1)
.fill(from)
.map((_, i) => addMinutesUTC(_, i));
case '7d':
return Array(7)
return Array(differenceDaysUTC(to, from) + 1)
.fill(from)
.map((_, i) => addDaysUTC(_, i));
case '30d':
return Array(30)
return Array(differenceDaysUTC(to, from) + 1)
.fill(from)
.map((_, i) => addDaysUTC(_, i));
case 'month':
Expand Down
8 changes: 8 additions & 0 deletions ui/src/utils/DateTimeUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import {
addMinutes,
addMonths,
differenceInCalendarDays,
differenceInHours,
differenceInMinutes,
getDaysInMonth,
isSameMinute,
isToday,
Expand Down Expand Up @@ -191,6 +193,12 @@ export const getDaysInMonthFromTimestamp = (value: UTCTimestamp): UTCTimestamp =
export const differenceDaysUTC = (left: UTCTimestamp, right: UTCTimestamp): number =>
differenceInCalendarDays(new Date(left), new Date(right));

export const differenceMinutesUTC = (left: UTCTimestamp, right: UTCTimestamp): number =>
differenceInMinutes(new Date(left), new Date(right));

export const differenceHoursUTC = (left: UTCTimestamp, right: UTCTimestamp): number =>
differenceInHours(new Date(left), new Date(right));

export const getMinutesUTC = (value: UTCTimestamp): UTCTimestamp => {
const elements = dateToUTCElements(new Date(value));

Expand Down