postgres-interval
Advanced tools
Comparing version 2.0.0 to 2.1.0
@@ -15,2 +15,3 @@ declare namespace PostgresInterval { | ||
toISOString(): string; | ||
toISOStringShort(): string; | ||
} | ||
@@ -17,0 +18,0 @@ } |
16
index.js
@@ -53,2 +53,10 @@ 'use strict' | ||
PostgresInterval.prototype.toISOString = PostgresInterval.prototype.toISO = function () { | ||
return toISOString.call(this, { short: false }) | ||
} | ||
PostgresInterval.prototype.toISOStringShort = function () { | ||
return toISOString.call(this, { short: true }) | ||
} | ||
function toISOString ({ short = false }) { | ||
const datePart = dateProperties | ||
@@ -62,4 +70,8 @@ .map(buildProperty, this) | ||
return 'P' + datePart + 'T' + timePart | ||
if (!timePart.length && !datePart.length) return 'PT0S' | ||
if (!timePart.length) return `P${datePart}` | ||
return `P${datePart}T${timePart}` | ||
function buildProperty (property) { | ||
@@ -74,2 +86,4 @@ let value = this[property] || 0 | ||
if (short && !value) return '' | ||
return value + propertiesISOEquivalent[property] | ||
@@ -76,0 +90,0 @@ } |
{ | ||
"name": "postgres-interval", | ||
"main": "index.js", | ||
"version": "2.0.0", | ||
"version": "2.1.0", | ||
"description": "Parse Postgres interval columns", | ||
@@ -6,0 +6,0 @@ "license": "MIT", |
@@ -48,8 +48,12 @@ # postgres-interval [![Build Status](https://travis-ci.org/bendrucker/postgres-interval.svg?branch=master)](https://travis-ci.org/bendrucker/postgres-interval) | ||
Returns an [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601#Durations) compliant string. | ||
Returns an [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601#Durations) compliant string, for example `P0Y0M0DT0H9M0S`. | ||
Also available as `interval.toISO()` for backwards compatibility. | ||
#### `interval.toISOStringShort()` -> `string` | ||
Returns an [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601#Durations) compliant string shortened to minimum length, for example `PT9M`. | ||
## License | ||
MIT © [Ben Drucker](http://bendrucker.me) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
7559
136
59