All files / src/data-types timestamp-type.ts

100% Statements 4/4
100% Branches 4/4
100% Functions 2/2
100% Lines 4/4

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27                    19x 19x           143x           143x      
import { AbstractDataType } from './abstract-data-type.ts';
 
/**
 * `TIMESTAMP WITHOUT TIME ZONE` (`DataTypes.TIMESTAMP`); values are `Date` objects whose local
 * wall-clock time is the stored time.
 *
 * @internal
 */
export class TimestampType extends AbstractDataType {
  /** Converts a driver string into a `Date` (local time). */
  readonly parse = (value: unknown): unknown =>
    typeof value === 'string' ? new Date(value) : value;
 
  /**
   * @param fsp - Fractional seconds precision.
   */
  constructor(fsp?: number) {
    super(
      'TIMESTAMP',
      fsp === undefined
        ? 'TIMESTAMP WITHOUT TIME ZONE'
        : `TIMESTAMP(${AbstractDataType.integer('TIMESTAMP precision', fsp)}) WITHOUT TIME ZONE`,
    );
    Object.freeze(this);
  }
}