Files
klz-cables.com/.pnpm-store/v10/files/d9/ae826d98574bad49172ae349d31832fe6d82a8cfaf2cc030045d9e895bfc965c45af5779a424cd0cbf12bc60f387c5be2a23ae935bb7f536b9b9db0d7ebbf6
Marc Mintel 5397309103
Some checks failed
Build & Deploy / 🔍 Prepare (push) Successful in 20s
Build & Deploy / 🧪 QA (push) Failing after 34s
Build & Deploy / 🏗️ Build (push) Has started running
Build & Deploy / 🚀 Deploy (push) Has been cancelled
Build & Deploy / 🧪 Smoke Test (push) Has been cancelled
Build & Deploy / ⚡ Lighthouse (push) Has been cancelled
Build & Deploy / 🔔 Notify (push) Has been cancelled
fix(products): fix breadcrumbs and product filtering (backport from main)
2026-02-24 16:04:21 +01:00

51 lines
1.3 KiB
Plaintext

import { GraphQLScalarType, Kind } from 'graphql';
// Taken from https://gist.github.com/langpavel/b30f3d507a47713b0c6e89016e4e9eb7
function serializeDate(value) {
if (value instanceof Date) {
return value.getTime();
}
else if (typeof value === 'number') {
return Math.trunc(value);
}
else if (typeof value === 'string') {
return Date.parse(value);
}
return null;
}
function parseDate(value) {
if (value === null) {
return null;
}
try {
return new Date(value);
}
catch (err) {
return null;
}
}
function parseDateFromLiteral(ast) {
if (ast.kind === Kind.INT) {
const num = parseInt(ast.value, 10);
return new Date(num);
}
else if (ast.kind === Kind.STRING) {
return parseDate(ast.value);
}
return null;
}
export const GraphQLTimestamp = /*#__PURE__*/ new GraphQLScalarType({
name: 'Timestamp',
description: 'The javascript `Date` as integer. Type represents date and time ' +
'as number of milliseconds from start of UNIX epoch.',
serialize: serializeDate,
parseValue: parseDate,
parseLiteral: parseDateFromLiteral,
extensions: {
codegenScalarType: 'Date | string | number',
jsonSchema: {
type: 'string',
format: 'unix-time',
},
},
});