@selldone/sdk-storefront
Version:
A TypeScript SDK to connect to your shop and build a fully functional storefront and website by simply developing a frontend web application. All backend operations are seamlessly managed by the serverless Selldone solution.
168 lines (167 loc) • 6.93 kB
TypeScript
/**
* Extends the Date prototype to add various utility methods.
*/
declare global {
interface Date {
printTime(): string;
printMonth(): string;
printDayWeek(): string;
setStart(): Date;
setEnd(): Date;
addDays(days: number): Date;
addHours(hours: number): Date;
addSeconds(seconds: number): Date;
diffSeconds(date: Date): number;
diffMinutes(date: Date): number;
diffHours(date: Date): number;
diffDays(date: Date): number;
isBeforeToday(): boolean;
isAfterToday(): boolean;
isSameDay(otherDate: Date): boolean;
isToday(): boolean;
}
interface String {
convertToLocalDate(): Date | null;
getFromOtherTimeString(date_end: string): string | null;
}
}
export declare class DateConverter {
/**
* Converts a datetime string or an object containing a date string to a local time Date object.
* If the `keep_only_date` flag is set, it will set the time to the start of the day.
*
* @param datetimeStr - A datetime string or an object containing a date string.
* @param keep_only_date - A flag to determine if only the date should be kept.
*
* @returns Date object representing the local time.
*/
static convertToLocalTime(datetimeStr: {
date: string;
} | string | null | undefined, keep_only_date?: boolean): Date | null;
/**
* Converts a timestamp into a short date string format, specifically for charts.
* The format can be adjusted based on the `small` and `time` parameters.
*
* @param timestamp - The timestamp to convert.
* @param small - Flag to determine if the month should be in short format.
* @param time - Flag to determine if the time should be included in the format.
*
* @returns A formatted date string or "Invalid date!" in case of an error.
*/
static ConvertTimestampToShortString(timestamp: number | Date, small?: boolean, time?: boolean): string;
/**
* Get local time string in various formats.
*
* @param datetimeStr - Input date in either string or Date format.
* @param added_seconds - Number of seconds to add to the date.
* @param isShort - Flag to use a short date format.
* @param isMicro - Flag to use a micro date format.
* @param noTime - Flag to omit the time.
*
* @returns A formatted date string or null in case of an error.
*/
static GetLocalTimeString(datetimeStr: string | Date, added_seconds?: number, isShort?: boolean, isMicro?: boolean, noTime?: boolean): string | null;
/**
* Gets a descriptive string indicating the time elapsed since `datetime_start` to now.
*
* @param datetime_start - The starting date/time.
* @param local - Optional locale setting.
* @param abstract - A flag to determine the string format.
*
* @returns A formatted string describing the elapsed time.
*/
static getFromNowString(datetime_start: Date | string, local?: string | null, abstract?: boolean): string | null;
/**
* Calculates the relative time difference between two dates and returns it as a string.
*
* @param datetime_start - The start date/time.
* @param datetime_end - The end date/time.
* @param local - Optional locale setting, defaults to the global `$language.full_local`.
* @param abstract - Determines if the returned string should use the "short" or "long" style.
*
* @returns A string indicating the relative time difference between `datetime_start` and `datetime_end`.
*/
static getFromOtherTimeString(datetime_start: Date | string, datetime_end: Date | string, local?: string | null, abstract?: boolean): string;
/**
* Returns the difference between the current time and a given datetime in the specified dimension.
*
* Supported Dimensions:
* - s: Seconds
* - m: Minutes
* - h: Hours
* - d: Days
*
* @param datetimeStr - The given datetime to compare with.
* @param dim - The dimension to represent the difference in (s/m/h/d).
*
* @returns The difference in the specified dimension or null if `datetimeStr` is not provided.
*/
static getFromNowNumber(datetimeStr: string, dim: "s" | "m" | "h" | "d"): number | null;
/**
* Computes the duration string between two datetime values. The result will be formatted as `d:H:M` or `d:H:M:S` based on the `has_second` flag.
*
* Examples:
* - For a duration of 1 day, 2 hours, 15 minutes, and 30 seconds:
* - Without seconds: "1d 2:15"
* - With seconds: "1d 2:15:30"
*
* @param datetime_start - The starting datetime.
* @param datetime_end - The ending datetime.
* @param has_second - Flag to determine whether the resulting string should include seconds.
*
* @returns A string representation of the duration between the two datetime values in `d:H:M` or `d:H:M:S` format.
* If the input datetime are invalid, returns an empty string.
*/
static getDurationOtherTimeString(datetime_start: Date | string, datetime_end: Date | string, has_second?: boolean): string;
/**
*
* @param created_at
* @returns {boolean}
*/
static isToday(created_at: Date | string): boolean;
/**
* Checks if a given date string is within a specified range of days.
*
* @param date_string - The date string to check.
* @param days - The number of days in the range.
* @param offset - The offset in days from the current date (default is 0).
* @returns A boolean indicating whether the date is within the specified day range.
*/
static inDayRange(date_string: string | null, days: number, offset?: number): boolean;
static inBetweenDates(test: Date, start: Date | null, end: Date | null): boolean;
/**
* Get start of day before (days) days.
*
* @param {int | null} days
* @param {string | date | null} origin_date
* @returns {null|Date}
* @constructor
*/
static GetStartOfDateBefore(days: number, origin_date?: Date | string | null): null | Date;
/**
* Get end of day before (days) days.
*
* @param {int | null} days
* @param {string | date | null} origin_date
* @returns {null|Date}
* @constructor
*/
static GetEndOfDateBefore(days: number, origin_date?: Date | string | null): null | Date;
/**
* Check two date in same day.
*
* @param {Date} d1
* @param {Date} d2
* @returns {boolean}
* @constructor
*/
static InSameDay(d1: Date, d2: Date): boolean;
static SecondsToString(duration: number): string;
/**
* Convert date to string for url query builder!
*
* @param date
* @returns {string|*}
*/
static dateToString(date: Date | string): string | any;
}