All files / src/data-types wall-clock.ts

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

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 20139x                             7x 7x      
const pad = (value: number, width = 2): string => String(value).padStart(width, '0');
 
/**
 * Formats dates as local wall-clock text, the stored form of `TIMESTAMP WITHOUT TIME ZONE`.
 *
 * @internal
 */
export class WallClock {
  /**
   * Formats a date in the process time zone.
   *
   * @param date - Date to format.
   * @returns `YYYY-MM-DD HH:MM:SS.mmm`.
   */
  format(date: Date): string {
    const day = `${pad(date.getFullYear(), 4)}-${pad(date.getMonth() + 1)}-${pad(date.getDate())}`;
    return `${day} ${pad(date.getHours())}:${pad(date.getMinutes())}:${pad(date.getSeconds())}.${pad(date.getMilliseconds(), 3)}`;
  }
}