@sixbell-telco/sdk
Version:
A collection of reusable components designed for use in Sixbell Telco Angular projects
126 lines (125 loc) • 4.98 kB
TypeScript
import dayjs from 'dayjs';
/**
* Supported display / parsing formats for date utilities.
* Internally all calculations use ISO `YYYY-MM-DD` and convert to the chosen format for display.
*/
export declare const SUPPORTED_DATE_FORMATS: readonly ["DD/MM/YYYY", "MM/DD/YYYY", "YYYY-MM-DD", "DD-MM-YYYY", "MM-DD-YYYY", "YYYY/MM/DD", "DD.MM.YYYY", "MM.DD.YYYY", "YYYY.MM.DD"];
/** Union type of all supported format strings. */
export type SupportedDateFormat = (typeof SUPPORTED_DATE_FORMATS)[number];
/**
* Supported time-only formats
*/
export declare const SUPPORTED_TIME_FORMATS: readonly ["HH:mm", "HH:mm:ss"];
export type SupportedTimeFormat = (typeof SUPPORTED_TIME_FORMATS)[number];
export declare const ISO_DATE_FORMAT: SupportedDateFormat;
export declare const TIME_MINUTES_FORMAT: SupportedTimeFormat;
export declare const TIME_SECONDS_FORMAT: SupportedTimeFormat;
export declare const TIME_12H_MINUTES_FORMAT = "h:mm A";
export declare const TIME_12H_SECONDS_FORMAT = "h:mm:ss A";
/**
* Quick action types for range picker
*/
export type QuickRangePreset = 'last7Days' | 'last30Days' | 'last6Months' | 'lastYear';
/**
* Date range representation
*/
export interface DateRange {
start: string;
end: string;
}
/**
* Reusable date utility service for date operations across the SDK.
* Provides consistent date handling, formatting, and range operations.
*/
export declare class DateUtils {
/**
* Convert a date string to ISO format (YYYY-MM-DD)
*/
static toISODate(date: string, format?: SupportedDateFormat): string;
/**
* Convert ISO date to display format
*/
static toDisplayDate(isoDate: string, format: SupportedDateFormat): string;
/** Build a combined date-time format string, e.g. `YYYY-MM-DD HH:mm:ss` */
static buildDateTimeFormat(dateFmt: SupportedDateFormat, timeFmt: SupportedTimeFormat): string;
/** Infer time format from a time string (returns seconds precision if length is 8) */
static inferTimeFormat(time: string | null | undefined): SupportedTimeFormat;
/** Current time formatted per the provided time format */
static timeNow(format?: SupportedTimeFormat): string;
/** Milliseconds since epoch for now */
static nowMillis(): number;
/** Convert ISO date + time string into epoch milliseconds using provided time format */
static toMillis(isoDate: string, time: string, timeFmt: SupportedTimeFormat): number | null;
/** Whether a given ISO date equals today (local) */
static isTodayISO(isoDate: string): boolean;
/** End-of-day string for the given time format */
static endOfDay(format: SupportedTimeFormat): string;
/** Start-of-day string for the given time format */
static startOfDay(format: SupportedTimeFormat): string;
/** Checks if the provided time string represents end-of-day */
static isEndOfDay(time: string | null | undefined): boolean;
/**
* Convert 24-hour time format to 12-hour format with AM/PM
* @param time24h Time in HH:mm or HH:mm:ss format
* @param includeSeconds Whether to include seconds in the output
* @returns Time in 12-hour format (h:mm A or h:mm:ss A)
*/
static to12HourFormat(time24h: string, includeSeconds?: boolean): string;
/**
* Generate range value string for calendar components (ISO/ISO format)
*/
static toRangeValue(range: DateRange | null): string;
/**
* Parse range value string from calendar components (ISO/ISO format)
*/
static parseRangeValue(value: string): DateRange | null;
/**
* Generate quick range based on preset
*/
static generateQuickRange(preset: QuickRangePreset): DateRange;
/**
* Generate a range representing the last N hours relative to now, including times.
* Returns ISO date range plus HH:mm:ss start/end time strings.
*/
static generateLastHoursRange(hours: number): {
range: DateRange;
startTime: string;
endTime: string;
};
/**
* Validate date range
*/
static isValidRange(range: DateRange | null): boolean;
/**
* Check if a date is valid
*/
static isValidDate(date: string): boolean;
/**
* Get today's date in ISO format
*/
static today(): string;
/**
* Get yesterday's date in ISO format
*/
static yesterday(): string;
/**
* Get tomorrow's date in ISO format
*/
static tomorrow(): string;
/**
* Add/subtract time from a date
*/
static addTime(date: string, amount: number, unit: dayjs.ManipulateType): string;
/**
* Get difference between two dates
*/
static diff(date1: string, date2: string, unit?: dayjs.QUnitType): number;
/**
* Check if date is between two dates (inclusive)
*/
static isBetween(date: string, start: string, end: string): boolean;
/**
* Format date with custom pattern
*/
static format(date: string, pattern: string): string;
}