@daiso-tech/core
Version:
The library offers flexible, framework-agnostic solutions for modern web applications, built on adaptable components that integrate seamlessly with popular frameworks like Next Js.
104 lines (103 loc) • 3.12 kB
TypeScript
/**
* @module TimeSpan
*/
import type { ISerializable } from "../../serde/contracts/_module-exports.js";
import { TO_MILLISECONDS, type ITimeSpan } from "../../time-span/contracts/_module-exports.js";
import type { IComparable } from "../../utilities/_module-exports.js";
/**
*
* IMPORT_PATH: `"@daiso-tech/core/time-span"`
* @group Implementations
*/
export type SerializedTimeSpan = {
version: "1";
timeInMs: number;
};
/**
*
* IMPORT_PATH: `"@daiso-tech/core/time-span"`
* @group Implementations
*/
export type TimeSpanFromDateRangeSettings = {
/**
* @default
* ```ts
* new Date()
* ```
*/
start?: Date;
/**
* @default
* ```ts
* new Date()
* ```
*/
end?: Date;
};
/**
* The `TimeSpan` class is used for representing time interval.
* `TimeSpan` cannot be negative.
*
* IMPORT_PATH: `"@daiso-tech/core/time-span"`
* @group Implementations
*/
export declare class TimeSpan implements ITimeSpan, ISerializable<SerializedTimeSpan>, IComparable<ITimeSpan> {
private readonly milliseconds;
private static secondInMilliseconds;
private static minuteInMilliseconds;
private static hourInMilliseconds;
private static dayInMilliseconds;
static deserialize(serializedValue: SerializedTimeSpan): TimeSpan;
private constructor();
equals(value: ITimeSpan): boolean;
gt(value: ITimeSpan): boolean;
gte(value: ITimeSpan): boolean;
lt(value: ITimeSpan): boolean;
lte(value: ITimeSpan): boolean;
serialize(): SerializedTimeSpan;
static fromMilliseconds(milliseconds: number): TimeSpan;
static fromSeconds(seconds: number): TimeSpan;
static fromMinutes(minutes: number): TimeSpan;
static fromHours(hours: number): TimeSpan;
static fromDays(days: number): TimeSpan;
static fromTimeSpan(timeSpan: ITimeSpan): TimeSpan;
static fromDateRange({ start, end, }: TimeSpanFromDateRangeSettings): TimeSpan;
addMilliseconds(milliseconds: number): TimeSpan;
addSeconds(seconds: number): TimeSpan;
addMinutes(minutes: number): TimeSpan;
addHours(hours: number): TimeSpan;
addDays(days: number): TimeSpan;
addTimeSpan(timeSpan: ITimeSpan): TimeSpan;
subtractMilliseconds(milliseconds: number): TimeSpan;
subtractSeconds(seconds: number): TimeSpan;
subtractMinutes(minutes: number): TimeSpan;
subtractHours(hours: number): TimeSpan;
subtractDays(days: number): TimeSpan;
subtractTimeSpan(timeSpan: ITimeSpan): TimeSpan;
multiply(value: number): TimeSpan;
divide(value: number): TimeSpan;
[TO_MILLISECONDS](): number;
toMilliseconds(): number;
toSeconds(): number;
toMinutes(): number;
toHours(): number;
toDays(): number;
/**
* Will return endDate relative to a given `startDate` argument.
*
* @default
* ```ts
* new Date()
* ```
*/
toEndDate(startDate?: Date): Date;
/**
* Will return startDate relative to a given `endDate` argument.
*
* @default
* ```ts
* new Date()
* ```
*/
toStartDate(endDate?: Date): Date;
}