Registry / database / postgres-interval

postgres-interval

JSON →
library4.0.2jsnpmunverified

Parse Postgres interval columns. v4.0.2 (stable) — mature, low-churn single-purpose package with TypeScript declarations. Parses default Postgres interval string format (e.g. '01:02:03') and returns an object with months, days, hours, minutes, seconds, milliseconds. Provides toPostgres(), toISOString(), toISOStringShort() methods. No validation — expects well-formed input. Minimal dependencies, focused on performance. Current version drops Node <12.

npm install postgres-interval
INSTALL
IMPORT
SIG · POSTGRES-INTERVAL
P
postgres-interval
databasejavascriptv4.0.2
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default
import parse from 'postgres-interval'
const parse = require('postgres-interval')
ESM default import; CommonJS require also works but preferred for TypeScript.
parse
import parse from 'postgres-interval'
import { parse } from 'postgres-interval'
The module exports a single function as default, not a named export.
Interval
import parse from 'postgres-interval'; const interval = parse('...')
import { Interval } from 'postgres-interval'
No named export for the Interval class; use typeof to get type if needed: type Interval = ReturnType<typeof parse>.

Parses a Postgres interval string and demonstrates all output methods.

import parse from 'postgres-interval'; const interval = parse('01:02:03'); console.log(interval); // { hours: 1, minutes: 2, seconds: 3 } console.log(interval.toPostgres()); // '1 hour 2 minutes 3 seconds' console.log(interval.toISOString()); // 'P0Y0M0DT1H2M3S' console.log(interval.toISOStringShort()); // 'PT1H2M3S'
Debug
Known issues
breakingVersion 4.0.0 dropped support for Node <12. Requires Node >=12.
fix
Upgrade Node to version 12 or later.
affects: >=4.0.0
gotchaInput is not validated; any malformed string may produce unexpected results or crash.
fix
Ensure input strings follow Postgres default interval format, e.g. 'HH:MM:SS' or '1 day 2 hours 3 minutes 4 seconds'.
affects: all
gotchaThe parser assumes default Postgres intervalstyle. If intervalstyle is changed (e.g., to postgres_verbose or sql_standard), outputs will not parse correctly.
fix
Set `intervalstyle` to `default` in Postgres before querying intervals.
affects: all
deprecatedinterval.toISO() is provided for backwards compatibility but deprecated in favor of interval.toISOString().
fix
Use interval.toISOString() instead.
affects: >=2.0.0
Errors
Common errors & fixes
require is not defined in ES module scope
Using CommonJS require in an ES module environment.
fix
Use import parse from 'postgres-interval' instead.
Upgrade
Version history
4.0.2latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
4 hits · last 30 days
node
4
Resources
postgres-interval — npm install postgres-interval · libregistry