@asadi/angular-date-components
Version:
`Angular Date Components` is a comprehensive angular library of date-related components designed to meet the needs of applications that require localization based on various calendar systems. While the package currently includes two powerful components (S
90 lines (89 loc) • 3.62 kB
TypeScript
/**
* A utility class for handling and parsing date and time strings.
* Provides methods to extract date parts, time parts, hours, and minutes from formatted date strings.
* This class is designed to work with ISO 8601-like datetime formats.
*/
export declare class ADCDateTimeTools {
/**
* Allowed date splitters for parsing date strings.
*/
private readonly dateSplitters;
/**
* Constructs a dynamic regex pattern for date splitters.
*
* @returns A string pattern containing allowed splitters.
*/
private getDateSplitterPattern;
/**
* Extracts the date portion (YYYY-MM-DD or YYYY/MM/DD) from a datetime string.
*
* @param source - A datetime string in the format `yyyy-MM-ddThh:mm:ss` or `yyyy-MM-dd`.
* @returns The extracted date in the format `yyyy-MM-dd` or `yyyy/MM/dd`.
* @throws If the source string is not a valid date string.
*
* @example
* const tools = new ADCDateTimeTools();
* console.log(tools.dateOnly('2024-11-12T15:30:00')); // Output: '2024-11-12'
*/
dateOnly(source: string): string;
/**
* Extracts the time portion (hh:mm:ss) from a datetime string.
*
* @param source - A datetime string in the format `yyyy-MM-ddThh:mm:ss` or `yyyy-MM-ddThh:mm`.
* @returns The extracted time in the format `hh:mm:ss` or `hh:mm`.
* @throws If the source string is not a valid datetime string.
*
* @example
* const tools = new ADCDateTimeTools();
* console.log(tools.timeOnly('2024-11-12T15:30:00')); // Output: '15:30:00'
*/
timeOnly(source: string): string;
/**
* Extracts the hour from a time string.
*
* @param source - A time string in the format `hh:mm:ss` or `hh:mm`.
* @returns The hour as a string.
* @throws If the source string is not a valid time string.
*
* @example
* const tools = new ADCDateTimeTools();
* console.log(tools.hour('15:45')); // Output: '15'
*/
hour(source: string): string;
/**
* Extracts the hour from a time string or returns a default value if the source is null or undefined.
*
* @param source - A time string in the format `hh:mm:ss` or `hh:mm`, or `null`/`undefined`.
* @param defaultHour - The default hour to return if the source is null or invalid.
* @returns The hour as a string or the default value.
*
* @example
* const tools = new ADCDateTimeTools();
* console.log(tools.hourOrDefault(null, '08')); // Output: '08'
*/
hourOrDefault(source: string | null | undefined, defaultHour: string): string;
/**
* Extracts the minutes from a time string.
*
* @param source - A time string in the format `hh:mm:ss` or `hh:mm`.
* @returns The minutes as a string.
* @throws If the source string is not a valid time string.
*
* @example
* const tools = new ADCDateTimeTools();
* console.log(tools.minutes('15:45')); // Output: '45'
*/
minutes(source: string): string;
/**
* Extracts the minutes from a time string or returns a default value if the source is null or undefined.
*
* @param source - A time string in the format `hh:mm:ss` or `hh:mm`, or `null`/`undefined`.
* @param defaultMinute - The default minute to return if the source is null or invalid.
* @returns The minutes as a string or the default value.
*
* @example
* const tools = new ADCDateTimeTools();
* console.log(tools.minutesOrDefault(null, '30')); // Output: '30'
*/
minutesOrDefault(source: string | null | undefined, defaultMinute: string): string;
}