zen: fix black reset date
This commit is contained in:
20
packages/console/core/src/util/date.test.ts
Normal file
20
packages/console/core/src/util/date.test.ts
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
import { describe, expect, test } from "bun:test"
|
||||||
|
import { getWeekBounds } from "./date"
|
||||||
|
|
||||||
|
describe("util.date.getWeekBounds", () => {
|
||||||
|
test("returns a Monday-based week for Sunday dates", () => {
|
||||||
|
const date = new Date("2026-01-18T12:00:00Z")
|
||||||
|
const bounds = getWeekBounds(date)
|
||||||
|
|
||||||
|
expect(bounds.start.toISOString()).toBe("2026-01-12T00:00:00.000Z")
|
||||||
|
expect(bounds.end.toISOString()).toBe("2026-01-19T00:00:00.000Z")
|
||||||
|
})
|
||||||
|
|
||||||
|
test("returns a seven day window", () => {
|
||||||
|
const date = new Date("2026-01-14T12:00:00Z")
|
||||||
|
const bounds = getWeekBounds(date)
|
||||||
|
|
||||||
|
const span = bounds.end.getTime() - bounds.start.getTime()
|
||||||
|
expect(span).toBe(7 * 24 * 60 * 60 * 1000)
|
||||||
|
})
|
||||||
|
})
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
export function getWeekBounds(date: Date) {
|
export function getWeekBounds(date: Date) {
|
||||||
const dayOfWeek = date.getUTCDay()
|
const offset = (date.getUTCDay() + 6) % 7
|
||||||
const start = new Date(date)
|
const start = new Date(date)
|
||||||
start.setUTCDate(date.getUTCDate() - dayOfWeek + 1)
|
start.setUTCDate(date.getUTCDate() - offset)
|
||||||
start.setUTCHours(0, 0, 0, 0)
|
start.setUTCHours(0, 0, 0, 0)
|
||||||
const end = new Date(start)
|
const end = new Date(start)
|
||||||
end.setUTCDate(start.getUTCDate() + 7)
|
end.setUTCDate(start.getUTCDate() + 7)
|
||||||
|
|||||||
Reference in New Issue
Block a user