UNPKG

gnablib

Version:

A lean, zero dependency library to provide a useful base for your project.

411 lines (410 loc) 17 kB
/*! Copyright 2024 the gnablib contributors MPL-1.1 */ import { BitReader } from '../primitive/BitReader.js'; import { BitWriter } from '../primitive/BitWriter.js'; import { WindowStr } from '../primitive/WindowStr.js'; import { ISerializer } from '../primitive/interfaces/ISerializer.js'; import { Duration, DurationExact } from './Duration.js'; declare const consoleDebugSymbol: unique symbol; declare class Core { protected readonly _d: DataView; protected readonly _pos: number; protected constructor(_d: DataView, _pos?: number); protected _year_iso(p: number): string; protected _month_iso(p: number): string; protected _day_iso(p: number): string; protected _date_iso(p: number, sep: string): string; protected _hour_iso(p: number): string; protected _minute_iso(p: number): string; protected _second_iso(p: number): string; protected _milli_iso(p: number): string; protected _micro_iso(p: number): string; protected _time_iso(p: number, sep: boolean): string; protected _date_valid(p: number): void; protected _time_valid(p: number): void; protected toUnixDays(p: number): number; protected timeToUs(p: number): number; protected static vetDate(y: number, m: number, d: number): void; protected static vetTime(h: number, i: number, s: number, u: number): void; protected static parseYear(to: DataView, p: number, input: WindowStr, strict: boolean, reset: () => void): Error | undefined; protected static parseMonth(to: DataView, p: number, input: WindowStr, strict: boolean, reset: () => void): Error | undefined; protected static parseDay(to: DataView, p: number, input: WindowStr, strict: boolean, reset: () => void): Error | undefined; protected static parseDateUndelim(to: DataView, p: number, input: WindowStr, strict: boolean, reset: () => void): Error | undefined; protected static parseDate(to: DataView, p: number, input: WindowStr, strict: boolean, reset: () => void): Error | undefined; protected static parseHour(to: DataView, p: number, input: WindowStr, strict: boolean, reset: () => void): Error | undefined; protected static parseMinute(to: DataView, p: number, input: WindowStr, strict: boolean, reset: () => void): Error | undefined; protected static parseSecond(to: DataView, p: number, input: WindowStr, strict: boolean, reset: () => void): Error | undefined; protected static parseMilli(to: DataView, p: number, input: WindowStr, strict: boolean, left: boolean, reset: () => void): Error | undefined; protected static parseMicro(to: DataView, p: number, input: WindowStr, strict: boolean, left: boolean, reset: () => void): Error | undefined; protected static parseTimeUndelim(to: DataView, p: number, input: WindowStr, strict: boolean, reset: () => void): Error | undefined; protected static parseTime(to: DataView, p: number, input: WindowStr, strict: boolean, reset: () => void): Error | undefined; protected static dateFromValue(to: DataView, p: number, v: number): void; protected static timeFromValue(to: DataView, p: number, v: number): void; protected static dateFromUnixDays(to: DataView, p: number, source: number): void; } export declare class Year extends Core implements ISerializer { static readonly storageBytes = 2; static readonly serialBits = 15; static get min(): Year; static get max(): Year; toString(): string; toIsoString(): string; toJSON(): number; valueOf(): number; serialize(target: BitWriter): void; get serialSizeBits(): number; get [Symbol.toStringTag](): string; [consoleDebugSymbol](): string; static new(year: number): Year; static newGregorian(year: number, ad?: boolean): Year; static newHolocene(year: number): Year; static fromDate(dt: Date): Year; static fromDateUtc(dt: Date): Year; static parse(input: WindowStr, strict?: boolean): Year; static now(): Year; static isLeap(y: number): boolean; static deserialize(src: BitReader): Year; } export declare class Month extends Core implements ISerializer { static readonly storageBytes = 1; static readonly serialBits = 4; static get min(): Month; static get max(): Month; toString(): string; toIsoString(): string; toJSON(): number; valueOf(): number; serialize(target: BitWriter): void; get serialSizeBits(): number; validate(): Month; get [Symbol.toStringTag](): string; [consoleDebugSymbol](): string; static new(month: number): Month; static fromDate(dt: Date): Month; static fromDateUtc(dt: Date): Month; static parse(input: WindowStr, strict?: boolean): Month; static now(): Month; static deserialize(src: BitReader): Month; static lastDay(month: number): number; static lastDay(month: number, year: number): number; } export declare class Day extends Core implements ISerializer { static readonly storageBytes = 1; static readonly serialBits = 5; static get min(): Day; static get max(): Day; toString(): string; toIsoString(): string; toJSON(): number; valueOf(): number; serialize(target: BitWriter): void; get serialSizeBits(): number; validate(): Day; get [Symbol.toStringTag](): string; [consoleDebugSymbol](): string; static new(day: number): Day; static fromDate(dt: Date): Day; static fromDateUtc(dt: Date): Day; static parse(input: WindowStr, strict?: boolean): Day; static now(): Day; static deserialize(src: BitReader): Day; } export declare class DateOnly extends Core implements ISerializer { static readonly storageBytes = 4; static readonly serialBits = 24; static get min(): DateOnly; static get max(): DateOnly; get year(): number; get month(): number; get day(): number; toString(sep?: string): string; toJSON(): number; toDate(): Date; toUnixDays(): number; toUnixTime(): number; toUnixTimeMs(): number; valueOf(): number; serialize(to: BitWriter): void; get serialSizeBits(): number; validate(): DateOnly; get [Symbol.toStringTag](): string; [consoleDebugSymbol](): string; addSafe(days: number): DateOnly; add(ys: number, ms?: number): DateOnly; static new(y: number, m: number, d: number): DateOnly; static fromValue(v: number): DateOnly; static fromUnixDays(d: number): DateOnly; static fromDate(dt: Date): DateOnly; static fromDateUtc(dt: Date): DateOnly; static fromUnixTime(s: number): DateOnly; static fromUnixTimeMs(ms: number): DateOnly; static parse(input: WindowStr, strict?: boolean): DateOnly; static now(): DateOnly; static nowUtc(): DateOnly; static deserialize(src: BitReader): DateOnly; static dayOfWeek(unixDays: number): number; } export declare class Hour extends Core implements ISerializer { static readonly storageBytes = 1; static readonly serialBits = 5; static get min(): Hour; static get max(): Hour; toString(): string; toIsoString(): string; toJSON(): number; valueOf(): number; serialize(target: BitWriter): void; get serialSizeBits(): number; validate(): Hour; get [Symbol.toStringTag](): string; [consoleDebugSymbol](): string; static new(hour: number): Hour; static fromDate(dt: Date): Hour; static fromDateUtc(dt: Date): Hour; static fromUnixTime(s: number): Hour; static fromUnixTimeMs(ms: number): Hour; static fromUnixTimeUs(us: number): Hour; static parse(input: WindowStr, strict?: boolean): Hour; static now(): Hour; static nowUtc(): Hour; static deserialize(src: BitReader): Hour; } export declare class Minute extends Core implements ISerializer { static readonly storageBytes = 1; static readonly serialBits = 6; static get min(): Minute; static get max(): Minute; toString(): string; toIsoString(): string; toJSON(): number; valueOf(): number; serialize(target: BitWriter): void; get serialSizeBits(): number; validate(): Minute; get [Symbol.toStringTag](): string; [consoleDebugSymbol](): string; static new(minute: number): Minute; static fromDate(dt: Date): Minute; static fromDateUtc(dt: Date): Minute; static fromUnixTime(src: number): Minute; static fromUnixTimeMs(src: number): Minute; static fromUnixTimeUs(src: number): Minute; static parse(input: WindowStr, strict?: boolean): Minute; static now(): Minute; static nowUtc(): Minute; static deserialize(src: BitReader): Minute; } export declare class Second extends Core implements ISerializer { static readonly storageBytes = 1; static readonly serialBits = 6; static get min(): Second; static get max(): Second; toString(): string; toIsoString(): string; toJSON(): number; valueOf(): number; serialize(target: BitWriter): void; get serialSizeBits(): number; validate(): Second; get [Symbol.toStringTag](): string; [consoleDebugSymbol](): string; static new(second: number): Second; static fromDate(dt: Date): Second; static fromUnixTime(s: number): Second; static fromUnixTimeMs(src: number): Second; static fromUnixTimeUs(src: number): Second; static parse(input: WindowStr, strict?: boolean): Second; static now(): Second; static deserialize(src: BitReader): Second; } export declare class Millisecond extends Core implements ISerializer { static readonly storageBytes = 2; static readonly serialBits = 10; static get min(): Millisecond; static get max(): Millisecond; valueOf(): number; toString(): string; toIsoString(): string; toJSON(): number; serialize(target: BitWriter): void; get serialSizeBits(): number; validate(): Millisecond; get [Symbol.toStringTag](): string; [consoleDebugSymbol](): string; static new(millisecond: number): Millisecond; static fromDate(dt: Date): Millisecond; static fromUnixTime(s: number): Millisecond; static fromUnixTimeMs(ms: number): Millisecond; static fromUnixTimeUs(us: number): Millisecond; static parse(input: WindowStr, strict?: boolean, left?: boolean): Millisecond; static now(): Millisecond; static deserialize(src: BitReader): Millisecond; } export declare class Microsecond extends Core implements ISerializer { static readonly storageBytes = 3; static readonly serialBits = 20; static get min(): Microsecond; static get max(): Microsecond; valueOf(): number; toString(): string; toIsoString(): string; toJSON(): number; serialize(target: BitWriter): void; get serialSizeBits(): number; validate(): Microsecond; get [Symbol.toStringTag](): string; [consoleDebugSymbol](): string; static new(microsecond: number): Microsecond; static fromDate(dt: Date): Microsecond; static fromUnixTime(s: number): Microsecond; static fromUnixTimeMs(ms: number): Microsecond; static fromUnixTimeUs(us: number): Microsecond; static parse(input: WindowStr, strict?: boolean, left?: boolean): Microsecond; static now(): Microsecond; static deserialize(src: BitReader): Microsecond; } export declare class TimeOnly extends Core implements ISerializer { static readonly storageBytes = 6; static readonly serialBits = 37; static get min(): TimeOnly; static get max(): TimeOnly; get hour(): number; get minute(): number; get second(): number; get microsecond(): number; toString(sep?: boolean): string; toJSON(): string; toMicroseconds(): number; toMilliseconds(): number; toSeconds(): number; valueOf(): number; serialize(to: BitWriter): void; get serialSizeBits(): number; validate(): TimeOnly; get [Symbol.toStringTag](): string; [consoleDebugSymbol](): string; static new(h: number, i: number, s: number, u: number): TimeOnly; static fromValue(v: number): TimeOnly; static fromUnixTimeUs(us: number): TimeOnly; static fromUnixTimeMs(ms: number): TimeOnly; static fromUnixTime(s: number): TimeOnly; static fromDate(date: Date): TimeOnly; static parse(input: WindowStr, strict?: boolean): TimeOnly; static now(): TimeOnly; static deserialize(src: BitReader): TimeOnly; } export declare class TimeOnlyMs extends Core implements ISerializer { static readonly storageBytes = 5; static readonly serialBits: number; static get min(): TimeOnlyMs; static get max(): TimeOnlyMs; get hour(): number; get minute(): number; get second(): number; get millisecond(): number; toString(sep?: boolean): string; toJSON(): string; toMicroseconds(): number; toMilliseconds(): number; toSeconds(): number; valueOf(): number; serialize(to: BitWriter): void; get serialSizeBits(): number; validate(): TimeOnlyMs; get [Symbol.toStringTag](): string; [consoleDebugSymbol](): string; static new(h: number, i: number, s: number, ms: number): TimeOnlyMs; static fromValue(v: number): TimeOnlyMs; static fromUnixTimeUs(us: number): TimeOnlyMs; static fromUnixTimeMs(ms: number): TimeOnlyMs; static fromUnixTime(s: number): TimeOnlyMs; static fromDate(date: Date): TimeOnlyMs; static parse(input: WindowStr, strict?: boolean): TimeOnlyMs; static now(): TimeOnlyMs; static deserialize(src: BitReader): TimeOnlyMs; } declare class DateTimeShared extends Core { static readonly storageBytes = 10; static readonly serialBits: number; get year(): number; get month(): number; get day(): number; get hour(): number; get minute(): number; get second(): number; get microsecond(): number; toString(dateTimeSep?: string): string; toJSON(): string; toUnixTime(): number; toUnixTimeMs(): number; serialize(to: BitWriter): void; get serialSizeBits(): number; protected _addDe(de: DurationExact, dv: DataView): void; protected _addDv(du: Duration, dv: DataView): void; protected _subDe(du: DurationExact, dv: DataView): void; protected _subDv(du: Duration, dv: DataView): void; protected cmp<T>(other: DateTimeShared, gt: T, lt: T, eq: T): T; private static _diff; private static _diffExact; protected diff(erl: DateTimeShared): Duration; protected diffExact(erl: DateTimeShared): DurationExact; } export declare class DateTimeLocal extends DateTimeShared implements ISerializer { static get min(): DateTimeLocal; static get max(): DateTimeLocal; toDate(): Date; valueOf(): string; validate(): DateTimeLocal; get [Symbol.toStringTag](): string; [consoleDebugSymbol](): string; add(du: DurationExact): DateTimeLocal; add(du: Duration): DateTimeLocal; sub(du: DurationExact): DateTimeLocal; sub(du: Duration): DateTimeLocal; diff(earlier: DateTimeLocal): Duration; diffExact(earlier: DateTimeLocal): DurationExact; gt(other: DateTimeLocal): boolean; gte(other: DateTimeLocal): boolean; lt(other: DateTimeLocal): boolean; lte(other: DateTimeLocal): boolean; eq(other: DateTimeLocal): boolean; neq(other: DateTimeLocal): boolean; static new(y: number, m: number, d: number, h: number, i: number, s: number, u: number): DateTimeLocal; static fromValue(v: string): DateTimeLocal; static fromDate(date: Date): DateTimeLocal; static fromUnixTimeMs(ms: number): DateTimeLocal; static fromUnixTime(s: number): DateTimeLocal; static now(): DateTimeLocal; static parse(input: WindowStr, strict?: boolean): DateTimeLocal; static deserialize(src: BitReader): DateTimeLocal; } export declare class DateTimeUtc extends DateTimeShared implements ISerializer { static get min(): DateTimeShared; static get max(): DateTimeShared; toString(dateTimeSep?: string): string; toDate(): Date; valueOf(): string; validate(): DateTimeUtc; get [Symbol.toStringTag](): string; [consoleDebugSymbol](): string; add(du: DurationExact): DateTimeUtc; add(du: Duration): DateTimeUtc; sub(du: DurationExact): DateTimeUtc; sub(du: Duration): DateTimeUtc; gt(other: DateTimeUtc): boolean; gte(other: DateTimeUtc): boolean; lt(other: DateTimeUtc): boolean; lte(other: DateTimeUtc): boolean; eq(other: DateTimeUtc): boolean; neq(other: DateTimeUtc): boolean; diff(earlier: DateTimeUtc): Duration; diffExact(earlier: DateTimeUtc): DurationExact; static new(y: number, m: number, d: number, h: number, i: number, s: number, u: number): DateTimeUtc; static fromValue(v: string): DateTimeUtc; static fromDate(date: Date): DateTimeUtc; static fromUnixTimeMs(ms: number): DateTimeUtc; static fromUnixTime(s: number): DateTimeUtc; static now(): DateTimeUtc; static parse(input: WindowStr, strict?: boolean): DateTimeUtc; static deserialize(src: BitReader): DateTimeUtc; } export {};