@codianz/better-date
Version:
The Date object easier to work with.
140 lines (139 loc) • 4.68 kB
TypeScript
import { DayOfWeekNumber } from "./day-of-week";
import { HHMM } from "./hhmm";
import { UTCOffsetMinutes } from "./utc-offset";
import { IYMD } from "./ymd";
declare class DateTimeCore {
private m_rawDate;
protected constructor(year: number, month: number, day: number, hour?: number, minute?: number, second?: number, ms?: number);
static fromValues(year: number, month: number, day: number, hour?: number, minute?: number, second?: number, ms?: number): DateTimeCore;
get msec(): number;
set msec(n: number);
get sec(): number;
set sec(n: number);
get min(): number;
set min(n: number);
get hour(): number;
set hour(n: number);
get dayOfWeek(): DayOfWeekNumber;
get day(): number;
set day(n: number);
get month(): number;
set month(n: number);
get year(): number;
set year(n: number);
get msecSinceEpoch(): number;
private fragments;
/**
* Format date-time string.
* @param fmt A string that specifies formatting.
*
* * %% : char of '%'
* * %YYYY : 4-digit year
* * %YY : 2-digit year
* * %MM : 2-digit month
* * %DD : 2-digit day
* * %hh : 2-digit hours
* * %mm : 2-digit minutes
* * %ss : 2-digit seconds
* * %ms : 3-digit milliseconds
* * %m : month
* * %d : day
* * %h : hours
* * %m : minutes
* * %s : seconds
*/
format(fmt: string): string;
toString(): string;
/**
* Get the difference in milliseconds.
* @param other
* @returns milliseconds
*/
diff(other: DateTimeCore): number;
}
type AnyUTCOffset = UTCOffsetMinutes | UTCOffsetMinutes | string | number;
export declare class BDate extends DateTimeCore {
private m_utcOffsetMinutes;
static isBDate(o: unknown): o is BDate;
clone(): BDate;
private constructor();
static now(): BDate;
static from(anyValue: string | Date | BDate): BDate;
/**
* Initialize it with a Javascript Date object. Use `getTimeZoneOffset()` for UTC offset.
* @param jsDate Javascript Date object
* @returns BDate
*/
static fromJsDate(jsDate: Date): BDate;
/**
* Initialize BDate as UTC in a Javascript Date object.
* @param jsDate Javascript Date object
* @returns BDate (UTC)
*/
static fromJsDateAsUTC(jsDate: Date): BDate;
/**
* Initialize a Javascript Date object with an arbitrary UTC offset.
* @param jsDate Javascript Date object
* @param utcOffset UTC offset string or minutes ("+09:00", "-02:00", 540, -120, ...)
* @returns BDate
*/
static fromJsDateWithOffset(jsDate: Date, utcOffset: AnyUTCOffset): BDate;
/**
* Initialize with UTC offset and local year, month, day, hour, minute, and second.
* @param utcOffset UTC offset string or minutes ("+09:00", "-02:00", 540, -120, ...)
* @param year
* @param month
* @param day
* @param hours
* @param minutes
* @param seconds
* @param ms
* @returns
*/
static fromLocalDateTimeValues(utcOffset: AnyUTCOffset, year: number, month: number, day: number, hour?: number, minute?: number, second?: number, ms?: number): BDate;
/**
* Initialize with UTC year, month, day, hour, minute, and second.
* @param year
* @param month
* @param day
* @param hours
* @param minutes
* @param seconds
* @param ms
* @returns BDate (UTC)
*/
static fromUTCDateTimeValues(year: number, month: number, day: number, hour?: number, minute?: number, second?: number, ms?: number): BDate;
toUTC(): BDate;
toISOString(): string;
toISOStringWithOffset(): string;
isUTC(): boolean;
get utcOffsetMinutes(): UTCOffsetMinutes;
/**
* Generate a LocalTime with a new UTC offset.
* @param utcOffset UTC offset string or minutes ("+09:00", "-02:00", 540, -120, ...)
* @returns BDate
*/
newUTCOffset(utcOffset: AnyUTCOffset): BDate;
toJsDate(): Date;
toYMD(): IYMD;
toHHMM(): HHMM;
static fromYMDHHMM(ymd: IYMD, hhmm: HHMM, utcOffset: AnyUTCOffset): BDate;
static fromYMD(ymd: IYMD, utcOffset: AnyUTCOffset): BDate;
/** calculations */
addMilliseconds(n: number): BDate;
addSeconds(n: number): BDate;
addMinutes(n: number): BDate;
addHours(n: number): BDate;
addDays(n: number): BDate;
addMonths(n: number): BDate;
addYears(n: number): BDate;
beginOfDay(): BDate;
endOfDay(): BDate;
beginOfWeek(): BDate;
endOfWeek(): BDate;
beginOfMonth(): BDate;
endOfMonth(): BDate;
beginOfYear(): BDate;
endOfYear(): BDate;
}
export {};