Skip to content

Commit 09b636d

Browse files
committed
fix: utc
1 parent e574dfb commit 09b636d

File tree

1 file changed

+36
-36
lines changed

1 file changed

+36
-36
lines changed

src/routes/stats/npm/index.tsx

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -131,25 +131,25 @@ const binningOptions = [
131131
label: 'Yearly',
132132
value: 'yearly',
133133
single: 'year',
134-
bin: d3.timeYear,
134+
bin: d3.utcYear,
135135
},
136136
{
137137
label: 'Monthly',
138138
value: 'monthly',
139139
single: 'month',
140-
bin: d3.timeMonth,
140+
bin: d3.utcMonth,
141141
},
142142
{
143143
label: 'Weekly',
144144
value: 'weekly',
145145
single: 'week',
146-
bin: d3.timeSunday,
146+
bin: d3.utcWeek,
147147
},
148148
{
149149
label: 'Daily',
150150
value: 'daily',
151151
single: 'day',
152-
bin: d3.timeDay,
152+
bin: d3.utcDay,
153153
},
154154
] as const
155155

@@ -222,7 +222,7 @@ function npmQueryOptions({
222222
packageGroups: z.infer<typeof packageGroupSchema>[]
223223
range: TimeRange
224224
}) {
225-
const now = d3.timeDay(new Date())
225+
const now = d3.utcDay(new Date())
226226
// Set to start of today to avoid timezone issues
227227
now.setHours(0, 0, 0, 0)
228228
let endDate = now
@@ -231,12 +231,12 @@ function npmQueryOptions({
231231
const getPackageCreationDate = async (packageName: string): Promise<Date> => {
232232
try {
233233
const response = await fetch(`https://registry.npmjs.org/${packageName}`)
234-
if (!response.ok) return d3.timeDay(new Date('2010-01-12')) // Fallback date
234+
if (!response.ok) return d3.utcDay(new Date('2010-01-12')) // Fallback date
235235
const data = await response.json()
236-
return d3.timeDay(new Date(data.time?.created || '2010-01-12'))
236+
return d3.utcDay(new Date(data.time?.created || '2010-01-12'))
237237
} catch (error) {
238238
console.error(`Error fetching creation date for ${packageName}:`, error)
239-
return d3.timeDay(new Date('2010-01-12')) // Fallback date
239+
return d3.utcDay(new Date('2010-01-12')) // Fallback date
240240
}
241241
}
242242

@@ -255,22 +255,22 @@ function npmQueryOptions({
255255
let startDate = (() => {
256256
switch (range) {
257257
case '7-days':
258-
return d3.timeDay.offset(now, -7)
258+
return d3.utcDay.offset(now, -7)
259259
case '30-days':
260-
return d3.timeDay.offset(now, -30)
260+
return d3.utcDay.offset(now, -30)
261261
case '90-days':
262-
return d3.timeDay.offset(now, -90)
262+
return d3.utcDay.offset(now, -90)
263263
case '180-days':
264-
return d3.timeDay.offset(now, -180)
264+
return d3.utcDay.offset(now, -180)
265265
case '365-days':
266-
return d3.timeDay.offset(now, -365)
266+
return d3.utcDay.offset(now, -365)
267267
case '730-days':
268-
return d3.timeDay.offset(now, -730)
268+
return d3.utcDay.offset(now, -730)
269269
case '1825-days':
270-
return d3.timeDay.offset(now, -1825)
270+
return d3.utcDay.offset(now, -1825)
271271
case 'all-time':
272272
// We'll handle this in the queryFn
273-
return d3.timeDay(new Date('2010-01-12')) // This will be overridden
273+
return d3.utcDay(new Date('2010-01-12')) // This will be overridden
274274
}
275275
})()
276276

@@ -297,11 +297,11 @@ function npmQueryOptions({
297297
const chunkRanges: { start: Date; end: Date }[] = []
298298

299299
while (currentStart < currentEnd) {
300-
const chunkEnd = d3.timeDay(new Date(currentEnd))
301-
const chunkStart = d3.timeDay.offset(currentEnd, -365)
300+
const chunkEnd = d3.utcDay(new Date(currentEnd))
301+
const chunkStart = d3.utcDay.offset(currentEnd, -365)
302302

303303
// Move the end date to the day before the start of the current chunk
304-
currentEnd = d3.timeDay.offset(chunkStart, -1)
304+
currentEnd = d3.utcDay.offset(chunkStart, -1)
305305

306306
chunkRanges.push({ start: chunkStart, end: chunkEnd })
307307
}
@@ -333,7 +333,7 @@ function npmQueryOptions({
333333
// Find the earliest non-zero download
334334
const firstNonZero = downloads.find((d) => d.downloads > 0)
335335
if (firstNonZero) {
336-
startDate = d3.timeDay(new Date(firstNonZero.day))
336+
startDate = d3.utcDay(new Date(firstNonZero.day))
337337
}
338338

339339
return { ...pkg, downloads }
@@ -495,26 +495,26 @@ function NpmStatsChart({
495495
const binOption = binningOptionsByType[binType]
496496
const binUnit = binningOptionsByType[binType].bin
497497

498-
const now = d3.timeDay(new Date())
498+
const now = d3.utcDay(new Date())
499499

500500
let startDate = (() => {
501501
switch (range) {
502502
case '7-days':
503-
return d3.timeDay.offset(now, -7)
503+
return d3.utcDay.offset(now, -7)
504504
case '30-days':
505-
return d3.timeDay.offset(now, -30)
505+
return d3.utcDay.offset(now, -30)
506506
case '90-days':
507-
return d3.timeDay.offset(now, -90)
507+
return d3.utcDay.offset(now, -90)
508508
case '180-days':
509-
return d3.timeDay.offset(now, -180)
509+
return d3.utcDay.offset(now, -180)
510510
case '365-days':
511-
return d3.timeDay.offset(now, -365)
511+
return d3.utcDay.offset(now, -365)
512512
case '730-days':
513-
return d3.timeDay.offset(now, -730)
513+
return d3.utcDay.offset(now, -730)
514514
case '1825-days':
515-
return d3.timeDay.offset(now, -1825)
515+
return d3.utcDay.offset(now, -1825)
516516
case 'all-time':
517-
return d3.timeDay(new Date('2010-01-12'))
517+
return d3.utcDay(new Date('2010-01-12'))
518518
}
519519
})()
520520

@@ -532,7 +532,7 @@ function NpmStatsChart({
532532
visiblePackages.forEach((pkg) => {
533533
pkg.downloads.forEach((d) => {
534534
// Clamp the data to the floor bin of the start date
535-
const date = d3.timeDay(new Date(d.day))
535+
const date = d3.utcDay(new Date(d.day))
536536
if (date < startDate) return
537537

538538
downloadsByDate.set(
@@ -546,7 +546,7 @@ function NpmStatsChart({
546546
return {
547547
...packageGroup,
548548
downloads: Array.from(downloadsByDate.entries()).map(
549-
([date, downloads]) => [d3.timeDay(new Date(date)), downloads]
549+
([date, downloads]) => [d3.utcDay(new Date(date)), downloads]
550550
) as [Date, number][],
551551
}
552552
})
@@ -565,7 +565,7 @@ function NpmStatsChart({
565565

566566
const downloads = binned.map((d) => ({
567567
name: packageGroup.packages[0].name,
568-
date: d3.timeDay(new Date(d[0])),
568+
date: d3.utcDay(new Date(d[0])),
569569
downloads: d[1],
570570
}))
571571

@@ -1918,18 +1918,18 @@ function RouteComponent() {
19181918
.flatMap((p) => p.downloads)
19191919
.sort(
19201920
(a, b) =>
1921-
d3.timeDay(a.day).getTime() -
1922-
d3.timeDay(b.day).getTime()
1921+
d3.utcDay(a.day).getTime() -
1922+
d3.utcDay(b.day).getTime()
19231923
)
19241924

19251925
// Get the binning unit and calculate partial bin boundaries
19261926
const binUnit = binOption.bin
1927-
const now = d3.timeDay(new Date())
1927+
const now = d3.utcDay(new Date())
19281928
const partialBinEnd = binUnit.floor(now)
19291929

19301930
// Filter downloads based on showDataMode for total downloads
19311931
const filteredDownloads = sortedDownloads.filter(
1932-
(d) => d3.timeDay(new Date(d.day)) < partialBinEnd
1932+
(d) => d3.utcDay(new Date(d.day)) < partialBinEnd
19331933
)
19341934

19351935
// Group downloads by bin using d3

0 commit comments

Comments
 (0)