import { Long } from "./long.ts";
export type TimestampOverrides = | "toExtendedJSON" | "fromExtendedJSON" | "inspect" | "_bsontype";export type LongWithoutOverrides = new ( low: unknown, high?: number, unsigned?: boolean,) => { [P in Exclude<keyof Long, TimestampOverrides>]: Long[P];};export const LongWithoutOverridesClass: LongWithoutOverrides = Long as unknown as LongWithoutOverrides;
export interface TimestampExtended { $timestamp: { t: number; i: number; };}
export class Timestamp extends LongWithoutOverridesClass { _bsontype = "Timestamp"; static readonly MAX_VALUE = Long.MAX_UNSIGNED_VALUE;
constructor(); constructor(value: Long | Timestamp); constructor(value: { t: number; i: number }); constructor( value: Timestamp | Long | { t: number; i: number } = new Long(), ) { const isLong = Long.isLong(value); const isTimestamp = value instanceof Timestamp; const low = isLong ? value.low : isTimestamp ? value.low : value.i; const high = isLong ? value.high : isTimestamp ? value.high : value.t; super(low, high, true); }
toJSON(): { $timestamp: string } { return { $timestamp: this.toString(), }; }
static fromInt(value: number): Timestamp { return new Timestamp(Long.fromInt(value, true)); }
static fromNumber(value: number): Timestamp { return new Timestamp(Long.fromNumber(value, true)); }
static fromBits(lowBits: number, highBits: number): Timestamp { return new Timestamp(new Long(lowBits, highBits)); }
static fromString(str: string, optRadix: number): Timestamp { return new Timestamp(Long.fromString(str, true, optRadix)); }
toExtendedJSON(): TimestampExtended { return { $timestamp: { t: this.high >>> 0, i: this.low >>> 0 } }; }
static fromExtendedJSON(doc: TimestampExtended): Timestamp { return new Timestamp(doc.$timestamp); }
[Symbol.for("Deno.customInspect")](): string { return `new Timestamp({ t: ${this.getHighBits()}, i: ${this.getLowBits()} })`; }}