A lightweight JavaScript library for parsing, formatting, and performing arithmetic on PostgreSQL interval strings. Current version 1.0.8 provides tools to create interval objects from 'HH:MM:SS' strings, format them with custom templates, and perform add, subtract, multiply, and diff operations. Unlike heavier libraries like moment.js or Luxon, pg-interval focuses solely on the PostgreSQL interval format, making it ideal for simple interval manipulations without dependencies. The library mutates objects for add/subtract but offers a clone option for multiply. It is primarily CommonJS with no ESM exports.
npm install pg-intervalNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Shows creation, formatting, addition, diff, and multiply (with clone) using pg-interval.
Clone the object manually or use multiply() with clone=true if you need immutability.
Use multiply(factor, true) to get a new instance without modifying the original.
Convert other interval formats to 'HH:MM:SS' before passing to pgi().
Avoid using intervals with hours > 23 or negative values; limit to timestamp-difference style intervals.
Change to `const pgi = require('pg-interval');`Use dynamic import: `const pgi = await import('pg-interval');` or convert to CommonJS.Ensure both operands are created via pgi(): `pgi('00:01:00').add(pgi('00:02:00'))`No dependency data recorded yet.