function createDateFactory
createDateFactory(customDayjs?: Dayjs): CreateDateFactoryReturn

Creates a date factory bound to a specific Dayjs instance.

This factory wraps a configured Dayjs instance and provides a unified createDate function that supports:

  • UTC parsing (highest priority)
  • Timezone-aware parsing
  • Local parsing
  • Optional strict parsing
  • Optional invalid-date throwing

Examples

Example 1

const { createDate } = createDateFactory();

const now = createDate();
const date = createDate('2024-01-01');
const utcDate = createDate('2024-01-01', undefined, { utc: true });
const tzDate = createDate('2024-01-01', undefined, { timezone: 'Asia/Kolkata' });

Parameters

optional
customDayjs: Dayjs

Optional custom Dayjs instance (useful for testing or plugin overrides)

Return Type

A factory object containing:

  • createDate: Unified date creation function
  • dayjs: The underlying Dayjs instance used by the factory

Usage

import { createDateFactory } from ".";