UNPKG

@tiller-ds/date

Version:

Date module of Tiller Design System

91 lines (90 loc) 5.75 kB
/** * Get the date format in desired language or ISO format if no language is provided. * * Currently supported languages are Croatian ('hr') and English ('en'). * @param {string} lang Language of the wished format, excluding it returns the standard ISO format * @param {boolean} time Determines whether to include time value in the format * @return {string} Date format in desired language */ export declare const getDateFormatByLang: (lang?: string | undefined, time?: boolean | undefined) => string; /** * Returns a Date object from a string or Date in desired language or ISO format if no language is provided. * If Date object is passed, it is returned as is. * * If no format is provided, the default ISO format 'yyyy-MM-dd' is inferred. * * @param {string} toFormat Date to be formatted * @param {string} format Format of the date (e.g. 'dd. MM. yyyy.' or 'MM/dd/yyyy') * @return {Date | null} Date object in desired language or null if the conversion is unsuccessful */ export declare const formatDate: (toFormat: string | null, format?: string | undefined) => Date | null; /** * Checks if the date is in the interval between minDate and/or maxDate. * * @param {Date | string | null} value Date to check if it is in interval * @param {Date} minDate Minimum date * @param {Date} maxDate Maximum date * @param {string} lang Language in which the date is formatted, excluding it implies the standard ISO format * @param {boolean} time Determines whether to include time value in the format * @return {boolean} A true or false value indicating whether the date is in the interval */ export declare const checkDatesInterval: (value: string | Date | null, minDate?: Date | undefined, maxDate?: Date | undefined, lang?: string | undefined, time?: boolean | undefined) => boolean; /** * Converts a value from 12-hour format 'hh:mm AM' or 'hh:mm PM' (not case-sensitive) * to 24-hour format 'hh:mm'. * * @param {string} value Value to be converted (in string format) * @return {string} Value in 24-hour format (in string format) */ export declare const convertTwelveHoursTimeTo24Hours: (value: string) => string; /** * Represents Tiller's date mask for handing over to the Masked Input component. * The mask has checks for month and day values of the date. * * Value example: 'mm/dd/yyyy' * * @param {string} value Date value for which the mask is created * @param {string} dateFormat Date format (if not provided, the default format inferred from 'lang' is used) * @param {string} lang Language for which the mask is created * @return {(string | RegExp)[]} Returns an array of strings and regular expressions that represent the mask */ export declare const dateMask: (value: string, dateFormat?: string | undefined, lang?: string | undefined) => (string | RegExp)[]; /** * Represents Tiller's date range mask for handing over to the Masked Input component. * The mask has checks for month and day values of the date. * * Value example: 'mm/dd/yyyy - mm/dd/yyyy' * * @param {string | null} value Date value for which the mask is created * @param {string} dateFormat Date format (if not provided, the default format inferred from 'lang' is used) * @param {string} lang Language for which the mask is created * @return {(string | RegExp)[]} Returns an array of strings and regular expressions that represent the mask */ export declare const dateRangeMask: (value: string | null, dateFormat?: string | undefined, lang?: string | undefined) => (string | RegExp)[]; /** * Represents Tiller's date time mask for handing over to the Masked Input component. * The mask has checks for month and day values of the date. * * Value example: 'mm/dd/yyyy hh:mm' * * @param {string | null} value Date value for which the mask is created * @param {string} dateFormat Date format (if not provided, the default format inferred from 'lang' is used) * @param {string} lang Language for which the mask is created * @param {boolean} twelveHours Determines whether the time is in 12-hour format * @return {(string | RegExp)[]} Returns an array of strings and regular expressions that represent the mask */ export declare const dateTimeMask: (value: string, dateFormat?: string | undefined, lang?: string | undefined, twelveHours?: boolean | undefined) => (string | RegExp)[]; /** * Represents Tiller's time mask for handing over to the Masked Input component. * * The mask has checks for month and day values of the date and supports 'hh:mm' and 'hh:mm AM/PM' formats. * * @param {string | null} value Date value for which the mask is created * @param {boolean} twelveHours Determines whether the time is in 12-hour format * @return {(string | RegExp)[]} Returns an array of strings and regular expressions that represent the mask */ export declare const timeMask: (value: string, twelveHours?: boolean | undefined) => (string | RegExp)[]; export declare const getMaskFromFormat: (value: string, format: string, twelveHours?: boolean | undefined) => (string | RegExp)[]; export declare const determineMonthInput: (value: string | null, position: number) => RegExp; export declare const determineDayInput: (value: string | null, position: number) => RegExp; export declare const determineHourInput: (value: string | null, twelveHours: boolean, position: number) => RegExp;