summaryrefslogtreecommitdiff
path: root/includes/external/school/node_modules/pronote-api/src/server/date.js
blob: a35cd5a8b35dec1017d8d5dea9fa880de2eb6fa1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
const { GraphQLScalarType, Kind } = require('graphql');

module.exports = new GraphQLScalarType({
    name: 'Date',
    description: 'Equivalent of the JS Date type',

    parseValue(value) {
        return new Date(value);
    },
    serialize(value) {
        return value.getTime();
    },
    parseLiteral(ast) {
        if (ast.kind === Kind.INT) {
            return new Date(parseInt(ast.value));
        }

        return new Date(ast.value);
    }
});