UNPKG

@wordpress/components

Version:
88 lines 3.13 kB
/** * Internal dependencies */ import type { InputState } from '../input-control/reducer/state'; import type { InputAction } from '../input-control/reducer/actions'; /** * Converts a date input to a UTC-normalized date for consistent date * manipulation. Timezoneless strings are interpreted using the timezone * offset from @wordpress/date settings. Date objects and timestamps * represent specific UTC instants. * * @param input Value to turn into a date. */ export declare function inputToDate(input: Date | string | number): Date; /** * Returns the start of day (midnight) as a browser-local Date for the calendar * day in the configured timezone in @wordpress/date settings. This is necessary * because date-fns's startOfDay operates in browser local time, which can cause * off-by-one-day bugs when browser and configured timezones differ. * * For example, if the UTC time is Nov 16, 01:00 UTC and configured timezone * is UTC-5, the date is Nov 15. This function returns a browser-local Date * at Nov 15, 00:00 (browser local midnight) so it matches calendar days. * * @param date A Date object normalized to UTC * @return A browser-local Date at midnight for the configured timezone date */ export declare function startOfDayInConfiguredTimezone(date: Date): Date; /** * Converts a 12-hour time to a 24-hour time. * @param hours * @param isPm */ export declare function from12hTo24h(hours: number, isPm: boolean): number; /** * Converts a 24-hour time to a 12-hour time. * @param hours */ export declare function from24hTo12h(hours: number): number; /** * Creates an InputControl reducer used to pad an input so that it is always a * given width. For example, the hours and minutes inputs are padded to 2 so * that '4' appears as '04'. * * @param pad How many digits the value should be. */ export declare function buildPadInputStateReducer(pad: number): (state: InputState, action: InputAction) => { _event?: import("react").SyntheticEvent; error: unknown; initialValue?: string; isDirty: boolean; isDragEnabled: boolean; isDragging: boolean; isPressEnterToChange: boolean; value?: string; }; /** * Returns the number of days in a month. * * @param year The year * @param month The month, zero-indexed (0-11) * * @return The number of days in the month */ export declare const getDaysInMonth: (year: number, month: number) => number; /** * Updates specific date fields in the configured timezone and returns a new * UTC date. * * @param date A Date object * @param updates Object with fields to update * @return A Date object normalized to UTC with the updated values */ export declare function setInConfiguredTimezone(date: Date, updates: Partial<{ year: number; month: number; date: number; hours: number; minutes: number; seconds: number; }>): Date; /** * Validates the target of a React event to ensure it is an input element and * that the input is valid. * @param event */ export declare function validateInputElementTarget(event: React.SyntheticEvent): boolean; //# sourceMappingURL=utils.d.ts.map