datetimebuddy
Version:
A lightweight, chainable DateTime utility for JavaScript and TypeScript with UTC support, formatting, and date math.
87 lines (85 loc) • 2.82 kB
text/typescript
declare class DateTimeBuddy {
private date;
private timeZone;
constructor(date?: Date | string | number, timeZone?: string);
static now(timeZone?: string): DateTimeBuddy;
static parse(dateStr: string, timeZone?: string): DateTimeBuddy;
static fromUnixTimestamp(seconds: number, timeZone?: string): DateTimeBuddy;
setTimeZone(tz: string): this;
getTimeZone(): string;
addDays(days: number): this;
subtractDays(days: number): this;
addHours(hours: number): this;
subtractHours(hours: number): this;
addMinutes(minutes: number): this;
subtractMinutes(minutes: number): this;
private getParts;
private getPart;
year(): number;
month(): number;
day(): number;
hour(): number;
minute(): number;
second(): number;
isBefore(other: Date | DateTimeBuddy): boolean;
isAfter(other: Date | DateTimeBuddy): boolean;
isSame(other: Date | DateTimeBuddy): boolean;
daysBetween(other: Date | DateTimeBuddy): number;
startOfDay(): DateTimeBuddy;
endOfDay(): DateTimeBuddy;
startOfMonth(): this;
endOfMonth(): this;
startOfYear(): this;
endOfYear(): this;
setDateComponents({ year, month, day, hour, minute, second, }: {
year?: number;
month?: number;
day?: number;
hour?: number;
minute?: number;
second?: number;
}): this;
format(formatStr: string): string;
diffIn(other: DateTimeBuddy, unit?: 'seconds' | 'minutes' | 'hours' | 'days'): number;
toDate(): Date;
toISOString(): string;
toUnixTimestamp(): number;
clone(): DateTimeBuddy;
applyOffset(offsetHours: number): DateTimeBuddy;
getWeekday(): string;
getDayOfWeek(): number;
getISOWeekday(): number;
getWeekNumber(): number;
addWeeks(weeks: number): this;
subtractWeeks(weeks: number): this;
startOfWeek(): DateTimeBuddy;
endOfWeek(): DateTimeBuddy;
currentWeek(): {
start: DateTimeBuddy;
end: DateTimeBuddy;
};
nextWeek(): {
start: DateTimeBuddy;
end: DateTimeBuddy;
};
previousWeek(): {
start: DateTimeBuddy;
end: DateTimeBuddy;
};
isLeapYear(): boolean;
toUTCString(): string;
toJSON(): string;
toLocaleString(locale?: string, options?: Intl.DateTimeFormatOptions): string;
toLocaleDateString(locale?: string, options?: Intl.DateTimeFormatOptions): string;
compare(other: DateTimeBuddy): number;
daysInMonth(): number;
isWeekend(): boolean;
equalsDateOnly(other: DateTimeBuddy): boolean;
fromNow(): string;
timeAgo(): string;
formatFriendly(locale?: string, options?: Intl.DateTimeFormatOptions): string;
isToday(): boolean;
isTomorrow(): boolean;
isYesterday(): boolean;
}
export { DateTimeBuddy };