File tree Expand file tree Collapse file tree 2 files changed +22
-2
lines changed
packages/console/core/src/util Expand file tree Collapse file tree 2 files changed +22
-2
lines changed Original file line number Diff line number Diff line change 1+ import { describe , expect , test } from "bun:test"
2+ import { getWeekBounds } from "./date"
3+
4+ describe ( "util.date.getWeekBounds" , ( ) => {
5+ test ( "returns a Monday-based week for Sunday dates" , ( ) => {
6+ const date = new Date ( "2026-01-18T12:00:00Z" )
7+ const bounds = getWeekBounds ( date )
8+
9+ expect ( bounds . start . toISOString ( ) ) . toBe ( "2026-01-12T00:00:00.000Z" )
10+ expect ( bounds . end . toISOString ( ) ) . toBe ( "2026-01-19T00:00:00.000Z" )
11+ } )
12+
13+ test ( "returns a seven day window" , ( ) => {
14+ const date = new Date ( "2026-01-14T12:00:00Z" )
15+ const bounds = getWeekBounds ( date )
16+
17+ const span = bounds . end . getTime ( ) - bounds . start . getTime ( )
18+ expect ( span ) . toBe ( 7 * 24 * 60 * 60 * 1000 )
19+ } )
20+ } )
Original file line number Diff line number Diff line change 11export function getWeekBounds ( date : Date ) {
2- const dayOfWeek = date . getUTCDay ( )
2+ const offset = ( date . getUTCDay ( ) + 6 ) % 7
33 const start = new Date ( date )
4- start . setUTCDate ( date . getUTCDate ( ) - dayOfWeek + 1 )
4+ start . setUTCDate ( date . getUTCDate ( ) - offset )
55 start . setUTCHours ( 0 , 0 , 0 , 0 )
66 const end = new Date ( start )
77 end . setUTCDate ( start . getUTCDate ( ) + 7 )
You can’t perform that action at this time.
0 commit comments