UNPKG

@ukbhra/common-utils

Version:

A collection of reusable utility functions for string, object, validation, and general operations in Node.js projects.

52 lines 1.92 kB
import dayjs from 'dayjs'; /** * Format a date into the specified format (default: YYYY-MM-DD) */ export declare const formatDate: (date: dayjs.ConfigType, format?: string, tz?: string) => string; /** * Get current timestamp in ISO or custom format */ export declare const now: (format?: string) => string; /** * Add time (days/hours/minutes etc.) * Only valid units for manipulation: 'year', 'month', 'week', 'day', 'hour', 'minute', 'second', 'millisecond' */ export declare const addTime: (date: dayjs.ConfigType, amount: number, unit: dayjs.ManipulateType) => Date; /** * Subtract time (days/hours/minutes etc.) * Only valid units for manipulation: 'year', 'month', 'week', 'day', 'hour', 'minute', 'second', 'millisecond' */ export declare const subtractTime: (date: dayjs.ConfigType, amount: number, unit: dayjs.ManipulateType) => Date; /** * Get difference between two dates in specified unit */ export declare const diffIn: (date1: dayjs.ConfigType, date2: dayjs.ConfigType, unit?: dayjs.OpUnitType, float?: boolean) => number; /** * Check if two dates are on same day */ export declare const isSameDay: (date1: dayjs.ConfigType, date2: dayjs.ConfigType) => boolean; /** * Check if a date is in the past */ export declare const isPast: (date: dayjs.ConfigType) => boolean; /** * Check if a date is in the future */ export declare const isFuture: (date: dayjs.ConfigType) => boolean; /** * Get human readable relative time (e.g., "3 hours ago") */ export declare const fromNow: (date: dayjs.ConfigType) => string; /** * Convert date to UTC */ export declare const toUTC: (date: dayjs.ConfigType) => string; /** * Convert to specific timezone */ export declare const toTimezone: (date: dayjs.ConfigType, tz: string) => string; /** * Parse a date with custom format */ export declare const parseDate: (input: string, format: string) => dayjs.Dayjs; //# sourceMappingURL=dateUtil.d.ts.map