Files
website/src/lib/cs-prices/steam.ts
Stan Runge abac077541
All checks were successful
Test and deploy staging / staging (push) Successful in 11m52s
ui changes and cs prices
2026-09-25 00:44:06 +00:00

24 lines
594 B
TypeScript

/** Parse the English UTC labels returned by Steam's market history endpoint. */
export function steamDate(value: string): string {
const match = /^(\w{3}) (\d{1,2}) (\d{4})(?: (\d{1,2}):)?/.exec(value);
if (!match) throw new Error(`Unknown Steam date: ${value}`);
const month = [
'Jan',
'Feb',
'Mar',
'Apr',
'May',
'Jun',
'Jul',
'Aug',
'Sep',
'Oct',
'Nov',
'Dec'
].indexOf(match[1]);
if (month < 0) throw new Error(`Unknown Steam month: ${value}`);
return new Date(
Date.UTC(Number(match[3]), month, Number(match[2]), Number(match[4] ?? 0))
).toISOString();
}