All checks were successful
Test and deploy staging / staging (push) Successful in 11m52s
24 lines
594 B
TypeScript
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();
|
|
}
|