Files
duckdb-ui/ts/pkgs/duckdb-data-values/src/DuckDBTimeTZValue.ts
Jeff Raymakers 0edb52054a add duckdb-ui-client & other ts pkgs (#10)
* add duckdb-ui-client & other ts pkgs

* workflow fixes

* fix working dir

* no sparse checkout; specify package.json path

* path to pnpm-lock.yaml

* add check & build test

* workflow step descriptions

* use comments & names

* one more naming tweak
2025-06-13 09:16:05 -07:00

43 lines
1.2 KiB
TypeScript

import {
getDuckDBTimeStringFromMicrosecondsInDay,
getOffsetStringFromSeconds,
} from './conversion/dateTimeStringConversion.js';
import { Json } from './Json.js';
import { SpecialDuckDBValue } from './SpecialDuckDBValue.js';
export class DuckDBTimeTZValue extends SpecialDuckDBValue {
public readonly micros: bigint;
public readonly offset: number;
constructor(micros: bigint, offset: number) {
super();
this.micros = micros;
this.offset = offset;
}
public toDuckDBString(): string {
return `${getDuckDBTimeStringFromMicrosecondsInDay(
this.micros,
)}${getOffsetStringFromSeconds(this.offset)}`;
}
public toJson(): Json {
return this.toDuckDBString();
}
private static TimeBits = 40;
private static OffsetBits = 24;
private static MaxOffset = 16 * 60 * 60 - 1; // ±15:59:59 = 57599 seconds
public static fromBits(bits: bigint): DuckDBTimeTZValue {
const micros = BigInt.asUintN(
DuckDBTimeTZValue.TimeBits,
bits >> BigInt(DuckDBTimeTZValue.OffsetBits),
);
const offset =
DuckDBTimeTZValue.MaxOffset -
Number(BigInt.asUintN(DuckDBTimeTZValue.OffsetBits, bits));
return new DuckDBTimeTZValue(micros, offset);
}
}