{"name":"postgres-interval","main":"index.js","version":"4.1.0","description":"Parse Postgres interval columns","license":"MIT","repository":{"type":"git","url":"git+https://github.com/bendrucker/postgres-interval.git"},"author":{"name":"Ben Drucker","email":"bvdrucker@gmail.com","url":"https://www.bendrucker.me"},"engines":{"node":">=12"},"scripts":{"test":"standard && tape test.js"},"keywords":["postgres","interval","parser"],"dependencies":{},"devDependencies":{"standard":"^17.0.0","tape":"^5.0.0"},"gitHead":"3f03b016ecb9479f3532dcbde8c7aa8826d80986","types":"./index.d.ts","_id":"postgres-interval@4.1.0","bugs":{"url":"https://github.com/bendrucker/postgres-interval/issues"},"homepage":"https://github.com/bendrucker/postgres-interval#readme","_nodeVersion":"26.4.0","_npmVersion":"11.17.0","dist":{"integrity":"sha512-nJLACcOHi2iyRuMJeW6CuIA0Dc0i1YEpRr26XDyHAfxPjYUJOFxwZjmOc5oFFctTTh/OlRAMlnlXEJvr170fJg==","shasum":"4fa34ec82bdf3d0a34a801e10fd4a03052e8d3f7","tarball":"http://registry-npm.ywwl.com/postgres-interval/download/postgres-interval-4.1.0.tgz","fileCount":5,"unpackedSize":14318,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIFVVkGykocMxSZpq9NNdnfiv2V5NVfuhwdhJoF+cpcQdAiEA1l5D76df3o8bJhemms4c4H3oD0HBuQShTwdlYhgzLV0="}],"size":4114,"noattachment":false,"key":"/postgres-interval/-/postgres-interval-4.1.0.tgz"},"_npmUser":{"name":"bendrucker","email":"bvdrucker@gmail.com"},"directories":{},"maintainers":[{"name":"bendrucker","email":"bvdrucker@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/postgres-interval_4.1.0_1782795235675_0.4367750335418028"},"_hasShrinkwrap":false,"readme":"# postgres-interval [![tests](https://github.com/bendrucker/postgres-interval/workflows/tests/badge.svg)](https://github.com/bendrucker/postgres-interval/actions?query=workflow%3Atests)\n\n> Parse Postgres interval columns\n\n\n## Install\n\n```sh\nnpm install --save postgres-interval\n```\n\n\n## Usage\n\n```js\nvar parse = require('postgres-interval')\nvar interval = parse('01:02:03')\n// => { hours: 1, minutes: 2, seconds: 3 }\ninterval.toPostgres()\n// 1 hour 2 minutes 3 seconds\ninterval.toISOString()\n// P0Y0M0DT1H2M3S\ninterval.toISOStringShort()\n// PT1H2M3S\n```\n\nThis package parses the default Postgres interval style. If you have changed [`intervalstyle`](https://www.postgresql.org/docs/current/runtime-config-client.html#GUC-INTERVALSTYLE), you will need to set it back to the default:\n\n```sql\nset intervalstyle to default;\n```\n\n## API\n\n#### `parse(pgInterval)` -> `interval`\n\n##### pgInterval\n\n*Required*  \nType: `string`\n\nA Postgres interval string.\n\nThis package is focused on parsing Postgres outputs. It optimizes for performance by assuming that inputs follow the default interval format. It does not perform any validation on the input. If any interval field is not found, its value will be set to `0` in the returned `interval`.\n\n#### `interval.toPostgres()` -> `string`\n\nReturns an interval string. This allows the interval object to be passed into prepared statements.\n\n#### `interval.toISOString()` -> `string`\n\nReturns an [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601#Durations) compliant string, for example `P0Y0M0DT0H9M0S`.\n\nAlso available as `interval.toISO()` for backwards compatibility.\n\n#### `interval.toISOStringShort()` -> `string`\n\nReturns an [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601#Durations) compliant string shortened to minimum length, for example `PT9M`.\n\n#### `interval.toTemporalDuration()` -> `Temporal.Duration`\n\nReturns a [`Temporal.Duration`](https://tc39.es/proposal-temporal/docs/duration.html) representing the interval.\n\nRequires `globalThis.Temporal`. It ships unflagged in Node 26+. On older runtimes, install a polyfill such as [`@js-temporal/polyfill`](https://www.npmjs.com/package/@js-temporal/polyfill) and assign it to `globalThis.Temporal`. The method throws if `Temporal` is unavailable.\n\nPostgres mixed-sign intervals (e.g. `1 mon -1 days`) throw a `RangeError`. `Temporal.Duration` requires all fields to share a single sign, which these intervals violate.\n\nThe `Temporal` types are not yet in the default TypeScript lib. To resolve the return type, your project needs Temporal lib types: the TypeScript lib once available, or the `@js-temporal/polyfill` types. This package adds no type dependency.\n\n## License\n\nMIT © [Ben Drucker](http://bendrucker.me)\n","publish_time":1782795235799,"_cnpm_publish_time":1782795235799,"dist-tags":{"latest":"4.1.0"}}