fix: parse Speedtest Tracker created_at as local time (#5751)
This commit is contained in:
1 parent
a0cc68798d
commit
b19549b601
2 files changed
+20
-1
No files matched your search
@@ -2,7 +2,7 @@ import { z } from "zod/v4";
|
|||||||
|
|
||||||
const createEnvelopeSchema = <T extends z.ZodType>(dataSchema: T) => z.object({ data: dataSchema });
|
const createEnvelopeSchema = <T extends z.ZodType>(dataSchema: T) => z.object({ data: dataSchema });
|
||||||
|
|
||||||
const parseTimestamp = (timestamp: string): Date => new Date(`${timestamp.replace(" ", "T")}Z`);
|
const parseTimestamp = (timestamp: string): Date => new Date(timestamp.replace(" ", "T"));
|
||||||
|
|
||||||
export const speedtestTrackerResultSchema = z.object({
|
export const speedtestTrackerResultSchema = z.object({
|
||||||
id: z.number().int(),
|
id: z.number().int(),
|
||||||
|
|||||||
@@ -0,0 +1,19 @@
|
|||||||
|
import { describe, expect, test } from "vitest";
|
||||||
|
|
||||||
|
import { speedtestTrackerResultSchema } from "../speedtest-tracker-types";
|
||||||
|
|
||||||
|
describe("speedtestTrackerResultSchema", () => {
|
||||||
|
test("parses created_at as Speedtest Tracker local wall time", () => {
|
||||||
|
const result = speedtestTrackerResultSchema.parse({
|
||||||
|
id: 1,
|
||||||
|
ping: 12,
|
||||||
|
download_bits: 100,
|
||||||
|
upload_bits: 50,
|
||||||
|
healthy: true,
|
||||||
|
created_at: "2026-05-18 18:30:01",
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(result.created_at.getHours()).toBe(18);
|
||||||
|
expect(result.created_at.getMinutes()).toBe(30);
|
||||||
|
});
|
||||||
|
});
|
||||||
Reference in new issue
Block a user