UNPKG

@statezero/core

Version:

The type-safe frontend client for StateZero - connect directly to your backend models with zero boilerplate

35 lines (34 loc) 1.4 kB
/** * Date parsing utilities for handling Django style date formats */ export class DateParsingHelpers { static SUPPORTED_FORMATS: { 'iso-8601': null; '%Y-%m-%d': string; '%Y-%m-%d %H:%M:%S': string; '%d/%m/%Y': string; '%m/%d/%Y': string; '%Y/%m/%d': string; '%d-%m-%Y': string; '%m-%d-%Y': string; '%B %d, %Y': string; '%d %B %Y': string; }; /** * Parse a date value using Django's format settings * @param {string|Date} value - The date value to parse * @param {string} fieldName - Name of the field (for schema lookup) * @param {Object} schema - The model schema containing format info * @param {string} timezone - The backend timezone (defaults to 'UTC') * @returns {Date|null} - Parsed Date object or null if invalid */ static parseDate(value: string | Date, fieldName: string, schema: Object, timezone?: string): Date | null; /** * Serialize a date using the field's configured format * @param {Date} date - The date to serialize * @param {string} fieldName - Name of the field (for schema lookup) * @param {Object} schema - The model schema containing format info * @returns {string|null} - Formatted date string or null if invalid */ static serializeDate(date: Date, fieldName: string, schema: Object): string | null; }