@coreui/react-pro
Version:
UI Components Library for React.js
81 lines (80 loc) • 4.91 kB
TypeScript
import type { LocalizedTimePartials } from './types';
/**
* Converts a 12-hour time format to a 24-hour time format.
* @param {('am' | 'pm')} abbr The abbreviation indicating AM or PM.
* @param {number} hour The hour to be converted.
* @returns {number} The hour in 24-hour format.
*/
export declare const convert12hTo24h: (abbr: "am" | "pm", hour: number) => number;
/**
* Converts a 24-hour time format to a 12-hour format.
* @param {number} hour The hour to be converted.
* @returns {number} The hour in 12-hour format.
*/
export declare const convert24hTo12h: (hour: number) => number;
/**
* Converts a time input into a Date object.
* @param {Date | string | null | undefined} time The time input to be converted.
* @returns {Date | null} The converted Date object or null if the input is falsy.
*/
export declare const convertTimeToDate: (time: Date | string | null | undefined) => Date | null;
/**
* Retrieves the AM/PM part of the specified date according to the given locale.
* @param {Date} date The date from which to extract the AM/PM part.
* @param {string} locale The locale to use for formatting.
* @returns {string} 'am' or 'pm' based on the given date and locale.
*/
export declare const getAmPm: (date: Date, locale: string) => "am" | "pm";
/**
* Formats an array of time values (hours, minutes, or seconds) according to the specified locale and partial.
* @param {number[]} values An array of time values to format.
* @param {string} locale The locale to use for formatting.
* @param {('hour' | 'minute' | 'second')} partial The type of time value to format.
* @returns {Array} An array of objects with the original value and its localized label.
*/
export declare const formatTimePartials: (values: number[], locale: string, partial: "hour" | "minute" | "second") => {
value: number;
label: string;
}[];
/**
* Generates localized time partials (hours, minutes, seconds) based on the given parameters.
* @param {string} locale The locale to use for generating localized time partials.
* @param {'auto' | boolean} ampm Determines whether to use 12-hour or 24-hour format. 'auto' decides based on locale.
* @param {boolean | number[] | Function} hours An array of hours, a boolean, or a function to generate hours.
* @param {boolean | number[] | Function} minutes An array of minutes, a boolean, or a function to generate minutes.
* @param {boolean | number[] | Function} seconds An array of seconds, a boolean, or a function to generate seconds.
* @returns {LocalizedTimePartials} An object containing arrays of localized time partials and a boolean indicating if 12-hour format is used.
*/
export declare const getLocalizedTimePartials: (locale: string, ampm?: "auto" | boolean, hours?: boolean | number[] | ((hour: number) => number[]), minutes?: boolean | number[] | ((minute: number) => number[]), seconds?: boolean | number[] | ((second: number) => number[])) => LocalizedTimePartials;
/**
* Gets the selected hour from a date object in either 12-hour or 24-hour format based on locale and preference.
* @param {Date | null} date The date object from which to extract the hour. If null, the function returns an empty string.
* @param {string} locale The locale to use when determining whether to return in 12-hour or 24-hour format.
* @param {'auto' | boolean} ampm Determines the format of the hour returned. 'auto' decides based on locale, true forces 12-hour format, and false forces 24-hour format.
* @returns {string | number} The hour in the specified format or an empty string if the date is null.
*/
export declare const getSelectedHour: (date: Date | null, locale: string, ampm?: "auto" | boolean) => number | "";
/**
* Gets the selected minutes from a date object.
* @param {Date | null} date The date object from which to extract the minutes. If null, the function returns an empty string.
* @returns {string | number} The minutes from the date or an empty string if the date is null.
*/
export declare const getSelectedMinutes: (date: Date | null) => number | "";
/**
* Gets the selected seconds from a date object.
* @param {Date | null} date The date object from which to extract the seconds. If null, the function returns an empty string.
* @returns {string | number} The seconds from the date or an empty string if the date is null.
*/
export declare const getSelectedSeconds: (date: Date | null) => number | "";
/**
* Determines if the given locale uses AM/PM format.
* @param {string} locale The locale to check.
* @returns {boolean} True if the locale uses AM/PM format, otherwise false.
*/
export declare const isAmPm: (locale: string) => boolean;
/**
* Validates if the given string represents a valid time.
* @param {string} time The time string to validate.
* @returns {boolean} True if the string is a valid time, otherwise false.
*/
export declare const isValidTime: (time: string) => number | false;