@@ -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 {
@@ -202,7 +203,7 @@ export function filterUsageByTimeRange<T>(
202203 if ( ! detailRecord || typeof detailRecord . timestamp !== 'string' ) {
203204 return ;
204205 }
205- const timestamp = Date . parse ( detailRecord . timestamp ) ;
206+ const timestamp = parseTimestampMs ( detailRecord . timestamp ) ;
206207 if ( Number . isNaN ( timestamp ) || timestamp < windowStart || timestamp > nowMs ) {
207208 return ;
208209 }
@@ -578,7 +579,7 @@ export function collectUsageDetails(usageData: unknown): UsageDetail[] {
578579 modelDetails . forEach ( ( detailRaw ) => {
579580 if ( ! isRecord ( detailRaw ) || typeof detailRaw . timestamp !== 'string' ) return ;
580581 const timestamp = detailRaw . timestamp ;
581- const timestampMs = Date . parse ( timestamp ) ;
582+ const timestampMs = parseTimestampMs ( timestamp ) ;
582583 const tokensRaw = isRecord ( detailRaw . tokens ) ? detailRaw . tokens : { } ;
583584 const latencyMs = extractLatencyMs ( detailRaw ) ;
584585 const firstByteLatencyMs =
@@ -663,7 +664,7 @@ export function collectUsageDetailsWithEndpoint(usageData: unknown): UsageDetail
663664 modelDetails . forEach ( ( detailRaw ) => {
664665 if ( ! isRecord ( detailRaw ) || typeof detailRaw . timestamp !== 'string' ) return ;
665666 const timestamp = detailRaw . timestamp ;
666- const timestampMs = Date . parse ( timestamp ) ;
667+ const timestampMs = parseTimestampMs ( timestamp ) ;
667668 const tokensRaw = isRecord ( detailRaw . tokens ) ? detailRaw . tokens : { } ;
668669 const latencyMs = extractLatencyMs ( detailRaw ) ;
669670 const firstByteLatencyMs =
@@ -776,7 +777,7 @@ export function calculateRecentPerMinuteRates(
776777 const timestamp =
777778 typeof detail . __timestampMs === 'number'
778779 ? detail . __timestampMs
779- : Date . parse ( detail . timestamp ) ;
780+ : parseTimestampMs ( detail . timestamp ) ;
780781 if ( ! Number . isFinite ( timestamp ) || timestamp < windowStart || timestamp > now ) {
781782 return ;
782783 }
@@ -1217,7 +1218,7 @@ export function buildHourlySeriesByModel(
12171218 const timestamp =
12181219 typeof detail . __timestampMs === 'number'
12191220 ? detail . __timestampMs
1220- : Date . parse ( detail . timestamp ) ;
1221+ : parseTimestampMs ( detail . timestamp ) ;
12211222 if ( ! Number . isFinite ( timestamp ) || timestamp <= 0 ) {
12221223 return ;
12231224 }
@@ -1276,7 +1277,7 @@ export function buildDailySeriesByModel(
12761277 const timestamp =
12771278 typeof detail . __timestampMs === 'number'
12781279 ? detail . __timestampMs
1279- : Date . parse ( detail . timestamp ) ;
1280+ : parseTimestampMs ( detail . timestamp ) ;
12801281 if ( ! Number . isFinite ( timestamp ) || timestamp <= 0 ) {
12811282 return ;
12821283 }
@@ -1502,7 +1503,7 @@ export function calculateStatusBarData(
15021503 const timestamp =
15031504 typeof detail . __timestampMs === 'number'
15041505 ? detail . __timestampMs
1505- : Date . parse ( detail . timestamp ) ;
1506+ : parseTimestampMs ( detail . timestamp ) ;
15061507 if (
15071508 ! Number . isFinite ( timestamp ) ||
15081509 timestamp <= 0 ||
@@ -1610,7 +1611,7 @@ export function calculateServiceHealthData(usageDetails: UsageDetail[]): Service
16101611 const timestamp =
16111612 typeof detail . __timestampMs === 'number'
16121613 ? detail . __timestampMs
1613- : Date . parse ( detail . timestamp ) ;
1614+ : parseTimestampMs ( detail . timestamp ) ;
16141615 if (
16151616 ! Number . isFinite ( timestamp ) ||
16161617 timestamp <= 0 ||
@@ -1820,7 +1821,7 @@ export function buildHourlyTokenBreakdown(
18201821 const timestamp =
18211822 typeof detail . __timestampMs === 'number'
18221823 ? detail . __timestampMs
1823- : Date . parse ( detail . timestamp ) ;
1824+ : parseTimestampMs ( detail . timestamp ) ;
18241825 if ( ! Number . isFinite ( timestamp ) || timestamp <= 0 ) return ;
18251826 const normalized = new Date ( timestamp ) ;
18261827 normalized . setMinutes ( 0 , 0 , 0 ) ;
@@ -1862,7 +1863,7 @@ export function buildDailyTokenBreakdown(usageData: unknown): TokenBreakdownSeri
18621863 const timestamp =
18631864 typeof detail . __timestampMs === 'number'
18641865 ? detail . __timestampMs
1865- : Date . parse ( detail . timestamp ) ;
1866+ : parseTimestampMs ( detail . timestamp ) ;
18661867 if ( ! Number . isFinite ( timestamp ) || timestamp <= 0 ) return ;
18671868 const dayLabel = formatDayLabel ( new Date ( timestamp ) ) ;
18681869 if ( ! dayLabel ) return ;
@@ -1939,7 +1940,7 @@ export function buildHourlyCostSeries(
19391940 const timestamp =
19401941 typeof detail . __timestampMs === 'number'
19411942 ? detail . __timestampMs
1942- : Date . parse ( detail . timestamp ) ;
1943+ : parseTimestampMs ( detail . timestamp ) ;
19431944 if ( ! Number . isFinite ( timestamp ) || timestamp <= 0 ) return ;
19441945 const normalized = new Date ( timestamp ) ;
19451946 normalized . setMinutes ( 0 , 0 , 0 ) ;
@@ -1974,7 +1975,7 @@ export function buildDailyCostSeries(
19741975 const timestamp =
19751976 typeof detail . __timestampMs === 'number'
19761977 ? detail . __timestampMs
1977- : Date . parse ( detail . timestamp ) ;
1978+ : parseTimestampMs ( detail . timestamp ) ;
19781979 if ( ! Number . isFinite ( timestamp ) || timestamp <= 0 ) return ;
19791980 const dayLabel = formatDayLabel ( new Date ( timestamp ) ) ;
19801981 if ( ! dayLabel ) return ;
0 commit comments