datemapper
Version:
A lightweight date utility for format conversion, validation, and date manipulation.
29 lines (28 loc) • 1.13 kB
TypeScript
/**
* Interface defining the structure of the date validation input.
*/
interface DateRangeInput {
from?: string;
to?: string;
}
/**
* Validates and normalizes date range inputs while applying timezone adjustments.
*
* - Ensures that the input dates are in a valid format.
* - Converts dates to the beginning (`from`) and end (`to`) of the day.
* - Ensures that `from` is not later than `to`.
* - Applies timezone adjustments to align with the provided timezone.
* - Provides default values if `from` or `to` is missing.
* - Supports customizable date format (defaults to `"YYYY-MM-DD"`).
*
* @param range - An object containing `from` and `to` date strings.
* @param timezone - The timezone to apply (default: UTC).
* @param format - The expected date format (default: "YYYY-MM-DD").
* @returns An object containing normalized `from` and `to` Date objects.
* @throws {DateValidationError} If the provided dates are invalid or incorrectly ordered.
*/
declare const validateDate: (range: DateRangeInput, timezone?: string, format?: string) => {
from: Date;
to: Date;
};
export default validateDate;