@@ -2,7 +2,7 @@ import { getTeamBySlug } from "@/api/team";
2
2
import { getLast24HoursRPCUsage } from "@/api/usage/rpc" ;
3
3
import { Alert , AlertDescription , AlertTitle } from "@/components/ui/alert" ;
4
4
import { Card , CardContent , CardHeader , CardTitle } from "@/components/ui/card" ;
5
- import { format } from "date-fns" ;
5
+ import { format , parseISO } from "date-fns" ;
6
6
import {
7
7
AlertTriangleIcon ,
8
8
CheckCircleIcon ,
@@ -63,6 +63,23 @@ export default async function RPCUsage(props: {
63
63
Number ( totalCounts . rateLimitedCount ) +
64
64
Number ( totalCounts . overageCount ) ;
65
65
66
+ const peakRateDate = ( ( ) => {
67
+ if ( peakRate . date ) {
68
+ try {
69
+ // treat peakRate.date as UTC
70
+ const date = peakRate . date . endsWith ( "Z" )
71
+ ? parseISO ( peakRate . date )
72
+ : // force the timestamp to be in UTC
73
+ parseISO ( `${ peakRate . date } Z` ) ;
74
+ return format ( date , "MMM d, HH:mm" ) ;
75
+ } catch ( e ) {
76
+ console . error ( "Error parsing peak rate date" , peakRate . date , e ) ;
77
+ return null ;
78
+ }
79
+ }
80
+ return null ;
81
+ } ) ( ) ;
82
+
66
83
return (
67
84
< div className = "container mx-auto space-y-8 py-6" >
68
85
< div className = "flex flex-col gap-2" >
@@ -113,9 +130,7 @@ export default async function RPCUsage(props: {
113
130
</ div >
114
131
< p className = "mt-1 text-muted-foreground text-xs" >
115
132
< ClockIcon className = "mr-1 inline h-3 w-3" />
116
- { peakRate . date
117
- ? format ( new Date ( `${ peakRate . date } Z` ) , "MMM d, HH:mm" )
118
- : "No Requests in last 24 hours" }
133
+ { peakRateDate ? peakRateDate : "No Requests in last 24 hours" }
119
134
</ p >
120
135
</ CardContent >
121
136
</ Card >
@@ -134,12 +149,14 @@ export default async function RPCUsage(props: {
134
149
< CheckCircleIcon className = "mr-1 h-3 w-3 text-green-500" />
135
150
< span >
136
151
{ /* we count both included and overage as included */ }
137
- { (
138
- ( ( Number ( totalCounts . includedCount ) +
139
- Number ( totalCounts . overageCount ) ) /
140
- Number ( totalRequests ) ) *
141
- 100
142
- ) . toFixed ( 1 ) }
152
+ { totalRequests === 0
153
+ ? "0.0"
154
+ : (
155
+ ( ( Number ( totalCounts . includedCount ) +
156
+ Number ( totalCounts . overageCount ) ) /
157
+ Number ( totalRequests ) ) *
158
+ 100
159
+ ) . toFixed ( 1 ) }
143
160
% successful requests
144
161
</ span >
145
162
</ div >
@@ -159,7 +176,7 @@ export default async function RPCUsage(props: {
159
176
< span >
160
177
{ /* if there are no requests, we show 100% success rate */ }
161
178
{ totalRequests === 0
162
- ? "100 "
179
+ ? "0.0 "
163
180
: (
164
181
( Number ( totalCounts . rateLimitedCount ) /
165
182
Number ( totalRequests ) ) *
0 commit comments