Skip to content
This repository has been archived by the owner on Feb 1, 2024. It is now read-only.

Commit

Permalink
feat(isostring): force-fail no TZ dates on UTC machines
Browse files Browse the repository at this point in the history
  • Loading branch information
Christina Harlow committed Feb 15, 2023
1 parent 8705282 commit ba8504c
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/isoStringScalar/isoStringScalar.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { GraphQLScalarType, Kind } from 'graphql';
import { DateTime } from 'luxon';
import { DateTime, Settings } from 'luxon';
import {
InternalServerError,
UserInputError,
Expand Down Expand Up @@ -58,6 +58,9 @@ export const isoStringScalar = new GraphQLScalarType({
);
}

// We only want explicitly UTC dates passed in. So we set the default TZ to US Central
// to force an error on any dates not set to any timezone (which might still fly if the machine is set to UTC).
Settings.defaultZoneName = 'America/Denver';
const isoDateTime = DateTime.fromISO(value, { setZone: true });
if (!(isoDateTime.offset === 0) || !isoDateTime.isValid) {
throw new UserInputError(
Expand Down

0 comments on commit ba8504c

Please sign in to comment.