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

Commit b920a32

Browse files
authored
Merge pull request #94 from scale8/realtime-graph-issue
Realtime graph issue
2 parents 75ca8ac + 5eadc6c commit b920a32

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

ui/src/hooks/chart/useChartPeriod.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import {
66
addMinutesUTC,
77
addMonthsUTC,
88
differenceDaysUTC,
9+
differenceHoursUTC,
10+
differenceMinutesUTC,
911
displayDayDetails,
1012
displayFullMonth,
1113
displayHourDetails,
@@ -19,6 +21,7 @@ import {
1921
stringToUTCTimestamp,
2022
subDaysUTC,
2123
subMonthsUTC,
24+
timestampDisplay,
2225
UTCNow,
2326
UTCTimestamp,
2427
} from '../../utils/DateTimeUtils';
@@ -137,19 +140,19 @@ export const datesFromChartPeriod = (
137140
): UTCTimestamp[] => {
138141
switch (period) {
139142
case 'day':
140-
return Array(24)
143+
return Array(differenceHoursUTC(to, from) + 1)
141144
.fill(from)
142145
.map((_, i) => addHoursUTC(_, i));
143146
case 'realtime':
144-
return Array(31)
147+
return Array(differenceMinutesUTC(to, from) + 1)
145148
.fill(from)
146149
.map((_, i) => addMinutesUTC(_, i));
147150
case '7d':
148-
return Array(7)
151+
return Array(differenceDaysUTC(to, from) + 1)
149152
.fill(from)
150153
.map((_, i) => addDaysUTC(_, i));
151154
case '30d':
152-
return Array(30)
155+
return Array(differenceDaysUTC(to, from) + 1)
153156
.fill(from)
154157
.map((_, i) => addDaysUTC(_, i));
155158
case 'month':

ui/src/utils/DateTimeUtils.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import {
44
addMinutes,
55
addMonths,
66
differenceInCalendarDays,
7+
differenceInHours,
8+
differenceInMinutes,
79
getDaysInMonth,
810
isSameMinute,
911
isToday,
@@ -191,6 +193,12 @@ export const getDaysInMonthFromTimestamp = (value: UTCTimestamp): UTCTimestamp =
191193
export const differenceDaysUTC = (left: UTCTimestamp, right: UTCTimestamp): number =>
192194
differenceInCalendarDays(new Date(left), new Date(right));
193195

196+
export const differenceMinutesUTC = (left: UTCTimestamp, right: UTCTimestamp): number =>
197+
differenceInMinutes(new Date(left), new Date(right));
198+
199+
export const differenceHoursUTC = (left: UTCTimestamp, right: UTCTimestamp): number =>
200+
differenceInHours(new Date(left), new Date(right));
201+
194202
export const getMinutesUTC = (value: UTCTimestamp): UTCTimestamp => {
195203
const elements = dateToUTCElements(new Date(value));
196204

0 commit comments

Comments
 (0)