@@ -459,33 +459,17 @@ function extractUniqueModels<T>(
459459 return uniq ( entries . map ( getModel ) . filter ( ( m ) : m is string => m != null && m !== '<synthetic>' ) ) ;
460460}
461461
462- /**
463- * Shared method for formatting dates with proper timezone handling
464- * @param dateStr - Input date string
465- * @param twoLine - Whether to format as two lines (true) or single line (false)
466- * @returns Formatted date string
467- */
468- function formatDateInternal ( dateStr : string , twoLine : boolean ) : string {
469- const date = new Date ( dateStr ) ;
470-
471- // Detect if the string includes UTC indicator (Z) or timezone offset (±HH:MM)
472- const hasTimezone = / Z | [ + - ] \d { 2 } : \d { 2 } / . test ( dateStr ) ;
473-
474- // Use UTC getters if timezone is specified, otherwise use local getters
475- const year = hasTimezone ? date . getUTCFullYear ( ) : date . getFullYear ( ) ;
476- const month = String ( hasTimezone ? date . getUTCMonth ( ) + 1 : date . getMonth ( ) + 1 ) . padStart ( 2 , '0' ) ;
477- const day = String ( hasTimezone ? date . getUTCDate ( ) : date . getDate ( ) ) . padStart ( 2 , '0' ) ;
478-
479- return twoLine ? `${ year } \n${ month } -${ day } ` : `${ year } -${ month } -${ day } ` ;
480- }
481-
482462/**
483463 * Formats a date string to YYYY-MM-DD format
484464 * @param dateStr - Input date string
485465 * @returns Formatted date string in YYYY-MM-DD format
486466 */
487467export function formatDate ( dateStr : string ) : string {
488- return formatDateInternal ( dateStr , false ) ;
468+ const date = new Date ( dateStr ) ;
469+ const year = date . getFullYear ( ) ;
470+ const month = String ( date . getMonth ( ) + 1 ) . padStart ( 2 , '0' ) ;
471+ const day = String ( date . getDate ( ) ) . padStart ( 2 , '0' ) ;
472+ return `${ year } -${ month } -${ day } ` ;
489473}
490474
491475/**
@@ -494,7 +478,11 @@ export function formatDate(dateStr: string): string {
494478 * @returns Formatted date string with newline separator (YYYY\nMM-DD)
495479 */
496480export function formatDateCompact ( dateStr : string ) : string {
497- return formatDateInternal ( dateStr , true ) ;
481+ const date = new Date ( dateStr ) ;
482+ const year = date . getFullYear ( ) ;
483+ const month = String ( date . getMonth ( ) + 1 ) . padStart ( 2 , '0' ) ;
484+ const day = String ( date . getDate ( ) ) . padStart ( 2 , '0' ) ;
485+ return `${ year } \n${ month } -${ day } ` ;
498486}
499487
500488/**
@@ -1257,30 +1245,16 @@ export async function loadSessionBlockData(
12571245
12581246if ( import . meta. vitest != null ) {
12591247 describe ( 'formatDate' , ( ) => {
1260- it ( 'formats UTC timestamps using UTC date' , ( ) => {
1261- // UTC timestamps should always use UTC date regardless of local timezone
1248+ it ( 'formats UTC timestamp to local date' , ( ) => {
1249+ // Test with UTC timestamps - results depend on local timezone
12621250 expect ( formatDate ( '2024-01-01T00:00:00Z' ) ) . toBe ( '2024-01-01' ) ;
12631251 expect ( formatDate ( '2024-12-31T23:59:59Z' ) ) . toBe ( '2024-12-31' ) ;
1264- expect ( formatDate ( '2024-01-01T12:00:00.000Z' ) ) . toBe ( '2024-01-01' ) ;
12651252 } ) ;
12661253
1267- it ( 'formats timezone offset strings using UTC date' , ( ) => {
1268- // Strings with timezone offsets should use UTC date
1269- expect ( formatDate ( '2024-01-01T00:00:00+00:00' ) ) . toBe ( '2024-01-01' ) ;
1270- expect ( formatDate ( '2024-01-01T00:00:00-05:00' ) ) . toBe ( '2024-01-01' ) ;
1271- expect ( formatDate ( '2024-12-31T23:59:59+08:00' ) ) . toBe ( '2024-12-31' ) ;
1272- } ) ;
1273-
1274- it ( 'formats local date strings using local date' , ( ) => {
1275- // Without timezone indicator, should use local date interpretation
1276- const localDate = new Date ( '2024-01-01T12:00:00' ) ;
1277- const expectedYear = localDate . getFullYear ( ) ;
1278- const expectedMonth = String ( localDate . getMonth ( ) + 1 ) . padStart ( 2 , '0' ) ;
1279- const expectedDay = String ( localDate . getDate ( ) ) . padStart ( 2 , '0' ) ;
1280- const expected = `${ expectedYear } -${ expectedMonth } -${ expectedDay } ` ;
1281-
1282- expect ( formatDate ( '2024-01-01' ) ) . toBe ( expected ) ;
1283- expect ( formatDate ( '2024-01-01T12:00:00' ) ) . toBe ( expected ) ;
1254+ it ( 'handles various date formats' , ( ) => {
1255+ expect ( formatDate ( '2024-01-01' ) ) . toBe ( '2024-01-01' ) ;
1256+ expect ( formatDate ( '2024-01-01T12:00:00' ) ) . toBe ( '2024-01-01' ) ;
1257+ expect ( formatDate ( '2024-01-01T12:00:00.000Z' ) ) . toBe ( '2024-01-01' ) ;
12841258 } ) ;
12851259
12861260 it ( 'pads single digit months and days' , ( ) => {
@@ -1291,30 +1265,15 @@ if (import.meta.vitest != null) {
12911265 } ) ;
12921266
12931267 describe ( 'formatDateCompact' , ( ) => {
1294- it ( 'formats UTC timestamps using UTC date with line break' , ( ) => {
1295- // UTC timestamps should always use UTC date regardless of local timezone
1268+ it ( 'formats UTC timestamp to local date with line break' , ( ) => {
12961269 expect ( formatDateCompact ( '2024-01-01T00:00:00Z' ) ) . toBe ( '2024\n01-01' ) ;
1297- expect ( formatDateCompact ( '2024-12-31T23:59:59Z' ) ) . toBe ( '2024\n12-31' ) ;
1298- expect ( formatDateCompact ( '2024-01-01T12:00:00.000Z' ) ) . toBe ( '2024\n01-01' ) ;
12991270 } ) ;
13001271
1301- it ( 'formats timezone offset strings using UTC date with line break' , ( ) => {
1302- // Strings with timezone offsets should use UTC date
1303- expect ( formatDateCompact ( '2024-01-01T00:00:00+00:00' ) ) . toBe ( '2024\n01-01' ) ;
1304- expect ( formatDateCompact ( '2024-01-01T00:00:00-05:00' ) ) . toBe ( '2024\n01-01' ) ;
1305- expect ( formatDateCompact ( '2024-12-31T23:59:59+08:00' ) ) . toBe ( '2024\n12-31' ) ;
1306- } ) ;
1307-
1308- it ( 'formats local date strings using local date with line break' , ( ) => {
1309- // Without timezone indicator, should use local date interpretation
1310- const localDate = new Date ( '2024-01-01T12:00:00' ) ;
1311- const expectedYear = localDate . getFullYear ( ) ;
1312- const expectedMonth = String ( localDate . getMonth ( ) + 1 ) . padStart ( 2 , '0' ) ;
1313- const expectedDay = String ( localDate . getDate ( ) ) . padStart ( 2 , '0' ) ;
1314- const expected = `${ expectedYear } \n${ expectedMonth } -${ expectedDay } ` ;
1315-
1316- expect ( formatDateCompact ( '2024-01-01' ) ) . toBe ( expected ) ;
1317- expect ( formatDateCompact ( '2024-01-01T12:00:00' ) ) . toBe ( expected ) ;
1272+ it ( 'handles various date formats' , ( ) => {
1273+ expect ( formatDateCompact ( '2024-12-31T23:59:59Z' ) ) . toBe ( '2024\n12-31' ) ;
1274+ expect ( formatDateCompact ( '2024-01-01' ) ) . toBe ( '2024\n01-01' ) ;
1275+ expect ( formatDateCompact ( '2024-01-01T12:00:00' ) ) . toBe ( '2024\n01-01' ) ;
1276+ expect ( formatDateCompact ( '2024-01-01T12:00:00.000Z' ) ) . toBe ( '2024\n01-01' ) ;
13181277 } ) ;
13191278
13201279 it ( 'pads single digit months and days' , ( ) => {
0 commit comments