or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

colors.mddata-formats.mddate-time.mdfinancial.mdgeographic.mdidentifiers.mdindex.mdnetwork.mdnumeric.mdspecialized.mdstring-text.mdutilities.md
tile.json

date-time.mddocs/

Date and Time Scalars

Date, time, and timestamp validation with ISO 8601 compliance and timezone support. These scalars handle various temporal data formats commonly used in applications.

Capabilities

Date Scalar

Validates ISO 8601 date format (YYYY-MM-DD).

/**
 * GraphQL scalar for ISO 8601 date format validation
 * Accepts dates in YYYY-MM-DD format
 */
const GraphQLDate: GraphQLScalarType;

Example Values:

  • "2023-12-25"
  • "2024-01-01"
  • "1990-06-15"

Time Scalar

Validates ISO 8601 time format with optional milliseconds.

/**
 * GraphQL scalar for ISO 8601 time format validation
 * Accepts time in HH:MM:SS[.sss] format
 */
const GraphQLTime: GraphQLScalarType;

Example Values:

  • "14:30:00"
  • "09:15:30.500"
  • "23:59:59"

DateTime Scalar

Validates ISO 8601 date-time format.

/**
 * GraphQL scalar for ISO 8601 date-time format validation
 * Accepts combined date and time representations
 */
const GraphQLDateTime: GraphQLScalarType;

Example Values:

  • "2023-12-25T14:30:00"
  • "2024-01-01T00:00:00.000"

DateTimeISO Scalar

Validates strict ISO 8601 date-time format with timezone information.

/**
 * GraphQL scalar for strict ISO 8601 date-time with timezone
 * Requires timezone offset or Z for UTC
 */
const GraphQLDateTimeISO: GraphQLScalarType;

Example Values:

  • "2023-12-25T14:30:00Z"
  • "2024-01-01T15:30:00+01:00"
  • "2023-06-15T09:00:00-07:00"

Timestamp Scalar

Validates Unix timestamps (seconds since epoch).

/**
 * GraphQL scalar for Unix timestamp validation
 * Accepts number of seconds since January 1, 1970 UTC
 */
const GraphQLTimestamp: GraphQLScalarType;

Example Values:

  • 1703520600 (2023-12-25T14:30:00Z)
  • 1704067200 (2024-01-01T00:00:00Z)

TimeZone Scalar

Validates IANA timezone identifiers.

/**
 * GraphQL scalar for IANA timezone identifier validation
 * Accepts standard timezone names from the IANA timezone database
 */
const GraphQLTimeZone: GraphQLScalarType;

Example Values:

  • "America/New_York"
  • "Europe/London"
  • "Asia/Tokyo"
  • "UTC"

UtcOffset Scalar

Validates UTC offset format.

/**
 * GraphQL scalar for UTC offset validation
 * Accepts offset in +/-HH:MM format
 */
const GraphQLUtcOffset: GraphQLScalarType;

Example Values:

  • "+00:00"
  • "-05:00"
  • "+09:30"
  • "-11:00"

Duration Scalar

Validates duration strings.

/**
 * GraphQL scalar for duration string validation
 * Accepts various duration string formats
 */
const GraphQLDuration: GraphQLScalarType;

ISO8601Duration Scalar

Validates ISO 8601 duration format.

/**
 * GraphQL scalar for ISO 8601 duration format validation
 * Accepts P[n]Y[n]M[n]DT[n]H[n]M[n]S format
 */
const GraphQLISO8601Duration: GraphQLScalarType;

Example Values:

  • "P1Y2M3DT4H5M6S" (1 year, 2 months, 3 days, 4 hours, 5 minutes, 6 seconds)
  • "PT30M" (30 minutes)
  • "P7D" (7 days)
  • "PT2H30M" (2 hours and 30 minutes)

LocalDate Scalar

Validates local date without timezone information.

/**
 * GraphQL scalar for local date validation
 * Accepts date in YYYY-MM-DD format without timezone
 */
const GraphQLLocalDate: GraphQLScalarType;

Example Values:

  • "2023-12-25"
  • "2024-02-29" (leap year)
  • "1999-12-31"

LocalTime Scalar

Validates local time without timezone information.

/**
 * GraphQL scalar for local time validation
 * Accepts time in HH:MM:SS[.sss] format without timezone
 */
const GraphQLLocalTime: GraphQLScalarType;

Example Values:

  • "14:30:00"
  • "09:15:30.500"
  • "00:00:00"

LocalDateTime Scalar

Validates local date-time without timezone information.

/**
 * GraphQL scalar for local date-time validation
 * Accepts combined date and time without timezone
 */
const GraphQLLocalDateTime: GraphQLScalarType;

Example Values:

  • "2023-12-25T14:30:00"
  • "2024-01-01T00:00:00.000"

LocalEndTime Scalar

Validates local end time with additional validation constraints.

/**
 * GraphQL scalar for local end time validation
 * Validates end time with business logic constraints
 */
const GraphQLLocalEndTime: GraphQLScalarType;

Usage Examples

import { 
  GraphQLDate, 
  GraphQLTime, 
  GraphQLDateTime,
  GraphQLTimeZone 
} from "graphql-scalars";

// In a GraphQL schema
const EventType = new GraphQLObjectType({
  name: "Event",
  fields: {
    startDate: { type: GraphQLDate },
    startTime: { type: GraphQLTime },
    createdAt: { type: GraphQLDateTime },
    timezone: { type: GraphQLTimeZone },
  },
});

// Using with type definitions
const typeDefs = `
  scalar Date
  scalar Time
  scalar DateTime
  scalar TimeZone
  
  type Event {
    startDate: Date
    startTime: Time
    createdAt: DateTime
    timezone: TimeZone
  }
`;

Type Definitions

// String constants for schema building
const Date: string;              // "scalar Date"
const Time: string;              // "scalar Time"  
const DateTime: string;          // "scalar DateTime"
const DateTimeISO: string;       // "scalar DateTimeISO"
const Timestamp: string;         // "scalar Timestamp"
const TimeZone: string;          // "scalar TimeZone"
const UtcOffset: string;         // "scalar UtcOffset"
const Duration: string;          // "scalar Duration"
const ISO8601Duration: string;   // "scalar ISO8601Duration"
const LocalDate: string;         // "scalar LocalDate"
const LocalTime: string;         // "scalar LocalTime"
const LocalDateTime: string;     // "scalar LocalDateTime"
const LocalEndTime: string;      // "scalar LocalEndTime"

Mock Data

// Mock data generators for testing
const DateMock: () => string;
const TimeMock: () => string;
const DateTimeMock: () => string;
const DateTimeISOMock: () => string;
const TimestampMock: () => number;
const TimeZoneMock: () => string;
const UtcOffsetMock: () => string;
const DurationMock: () => string;
const ISO8601DurationMock: () => string;
const LocalDateMock: () => string;
const LocalTimeMock: () => string;
const LocalDateTimeMock: () => string;
const LocalEndTimeMock: () => string;