Last active July 28, 2023 08:46
Save langpavel/b30f3d507a47713b0c6e89016e4e9eb7 to your computer and use it in GitHub Desktop.
GraphQLTimestamp.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters import { Kind } from 'graphql/language'; import { GraphQLScalarType } from 'graphql'; 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; } const TimestampType = 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, }); export default TimestampType;You can’t perform that action at this time.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4