@@ -13,6 +13,7 @@ import {
1313 finalizeLatencyStats ,
1414} from './usage/latency' ;
1515import { maskApiKey } from './format' ;
16+ import { parseTimestampMs } from './timestamp' ;
1617
1718export type { DurationFormatOptions , LatencyStats } from './usage/latency' ;
1819export {
@@ -195,7 +196,7 @@ export function filterUsageByTimeRange<T>(
195196 if ( ! detailRecord || typeof detailRecord . timestamp !== 'string' ) {
196197 return ;
197198 }
198- const timestamp = Date . parse ( detailRecord . timestamp ) ;
199+ const timestamp = parseTimestampMs ( detailRecord . timestamp ) ;
199200 if ( Number . isNaN ( timestamp ) || timestamp < windowStart || timestamp > nowMs ) {
200201 return ;
201202 }
@@ -545,7 +546,7 @@ export function collectUsageDetails(usageData: unknown): UsageDetail[] {
545546 modelDetails . forEach ( ( detailRaw ) => {
546547 if ( ! isRecord ( detailRaw ) || typeof detailRaw . timestamp !== 'string' ) return ;
547548 const timestamp = detailRaw . timestamp ;
548- const timestampMs = Date . parse ( timestamp ) ;
549+ const timestampMs = parseTimestampMs ( timestamp ) ;
549550 const tokensRaw = isRecord ( detailRaw . tokens ) ? detailRaw . tokens : { } ;
550551 const latencyMs = extractLatencyMs ( detailRaw ) ;
551552 details . push ( {
@@ -618,7 +619,7 @@ export function collectUsageDetailsWithEndpoint(usageData: unknown): UsageDetail
618619 modelDetails . forEach ( ( detailRaw ) => {
619620 if ( ! isRecord ( detailRaw ) || typeof detailRaw . timestamp !== 'string' ) return ;
620621 const timestamp = detailRaw . timestamp ;
621- const timestampMs = Date . parse ( timestamp ) ;
622+ const timestampMs = parseTimestampMs ( timestamp ) ;
622623 const tokensRaw = isRecord ( detailRaw . tokens ) ? detailRaw . tokens : { } ;
623624 const latencyMs = extractLatencyMs ( detailRaw ) ;
624625 details . push ( {
@@ -721,7 +722,7 @@ export function calculateRecentPerMinuteRates(
721722 const timestamp =
722723 typeof detail . __timestampMs === 'number'
723724 ? detail . __timestampMs
724- : Date . parse ( detail . timestamp ) ;
725+ : parseTimestampMs ( detail . timestamp ) ;
725726 if ( ! Number . isFinite ( timestamp ) || timestamp < windowStart || timestamp > now ) {
726727 return ;
727728 }
@@ -1131,7 +1132,7 @@ export function buildHourlySeriesByModel(
11311132 const timestamp =
11321133 typeof detail . __timestampMs === 'number'
11331134 ? detail . __timestampMs
1134- : Date . parse ( detail . timestamp ) ;
1135+ : parseTimestampMs ( detail . timestamp ) ;
11351136 if ( ! Number . isFinite ( timestamp ) || timestamp <= 0 ) {
11361137 return ;
11371138 }
@@ -1190,7 +1191,7 @@ export function buildDailySeriesByModel(
11901191 const timestamp =
11911192 typeof detail . __timestampMs === 'number'
11921193 ? detail . __timestampMs
1193- : Date . parse ( detail . timestamp ) ;
1194+ : parseTimestampMs ( detail . timestamp ) ;
11941195 if ( ! Number . isFinite ( timestamp ) || timestamp <= 0 ) {
11951196 return ;
11961197 }
@@ -1416,7 +1417,7 @@ export function calculateStatusBarData(
14161417 const timestamp =
14171418 typeof detail . __timestampMs === 'number'
14181419 ? detail . __timestampMs
1419- : Date . parse ( detail . timestamp ) ;
1420+ : parseTimestampMs ( detail . timestamp ) ;
14201421 if (
14211422 ! Number . isFinite ( timestamp ) ||
14221423 timestamp <= 0 ||
@@ -1524,7 +1525,7 @@ export function calculateServiceHealthData(usageDetails: UsageDetail[]): Service
15241525 const timestamp =
15251526 typeof detail . __timestampMs === 'number'
15261527 ? detail . __timestampMs
1527- : Date . parse ( detail . timestamp ) ;
1528+ : parseTimestampMs ( detail . timestamp ) ;
15281529 if (
15291530 ! Number . isFinite ( timestamp ) ||
15301531 timestamp <= 0 ||
@@ -1734,7 +1735,7 @@ export function buildHourlyTokenBreakdown(
17341735 const timestamp =
17351736 typeof detail . __timestampMs === 'number'
17361737 ? detail . __timestampMs
1737- : Date . parse ( detail . timestamp ) ;
1738+ : parseTimestampMs ( detail . timestamp ) ;
17381739 if ( ! Number . isFinite ( timestamp ) || timestamp <= 0 ) return ;
17391740 const normalized = new Date ( timestamp ) ;
17401741 normalized . setMinutes ( 0 , 0 , 0 ) ;
@@ -1776,7 +1777,7 @@ export function buildDailyTokenBreakdown(usageData: unknown): TokenBreakdownSeri
17761777 const timestamp =
17771778 typeof detail . __timestampMs === 'number'
17781779 ? detail . __timestampMs
1779- : Date . parse ( detail . timestamp ) ;
1780+ : parseTimestampMs ( detail . timestamp ) ;
17801781 if ( ! Number . isFinite ( timestamp ) || timestamp <= 0 ) return ;
17811782 const dayLabel = formatDayLabel ( new Date ( timestamp ) ) ;
17821783 if ( ! dayLabel ) return ;
@@ -1853,7 +1854,7 @@ export function buildHourlyCostSeries(
18531854 const timestamp =
18541855 typeof detail . __timestampMs === 'number'
18551856 ? detail . __timestampMs
1856- : Date . parse ( detail . timestamp ) ;
1857+ : parseTimestampMs ( detail . timestamp ) ;
18571858 if ( ! Number . isFinite ( timestamp ) || timestamp <= 0 ) return ;
18581859 const normalized = new Date ( timestamp ) ;
18591860 normalized . setMinutes ( 0 , 0 , 0 ) ;
@@ -1888,7 +1889,7 @@ export function buildDailyCostSeries(
18881889 const timestamp =
18891890 typeof detail . __timestampMs === 'number'
18901891 ? detail . __timestampMs
1891- : Date . parse ( detail . timestamp ) ;
1892+ : parseTimestampMs ( detail . timestamp ) ;
18921893 if ( ! Number . isFinite ( timestamp ) || timestamp <= 0 ) return ;
18931894 const dayLabel = formatDayLabel ( new Date ( timestamp ) ) ;
18941895 if ( ! dayLabel ) return ;
0 commit comments