postgres-date
Advanced tools
Comparing version 1.0.7 to 2.0.0
50
index.js
'use strict' | ||
var DATE_TIME = /(\d{1,})-(\d{2})-(\d{2}) (\d{2}):(\d{2}):(\d{2})(\.\d{1,})?.*?( BC)?$/ | ||
var DATE = /^(\d{1,})-(\d{2})-(\d{2})( BC)?$/ | ||
var TIME_ZONE = /([Z+-])(\d{2})?:?(\d{2})?:?(\d{2})?/ | ||
var INFINITY = /^-?infinity$/ | ||
const DATE_TIME = /(\d{1,})-(\d{2})-(\d{2}) (\d{2}):(\d{2}):(\d{2})(\.\d{1,})?.*?( BC)?$/ | ||
const DATE = /^(\d{1,})-(\d{2})-(\d{2})( BC)?$/ | ||
const TIME_ZONE = /([Z+-])(\d{2})?:?(\d{2})?:?(\d{2})?/ | ||
const INFINITY = /^-?infinity$/ | ||
@@ -13,3 +13,3 @@ module.exports = function parseDate (isoDate) { | ||
} | ||
var matches = DATE_TIME.exec(isoDate) | ||
const matches = DATE_TIME.exec(isoDate) | ||
@@ -21,4 +21,4 @@ if (!matches) { | ||
var isBC = !!matches[8] | ||
var year = parseInt(matches[1], 10) | ||
const isBC = !!matches[8] | ||
let year = parseInt(matches[1], 10) | ||
if (isBC) { | ||
@@ -28,13 +28,13 @@ year = bcYearToNegativeYear(year) | ||
var month = parseInt(matches[2], 10) - 1 | ||
var day = matches[3] | ||
var hour = parseInt(matches[4], 10) | ||
var minute = parseInt(matches[5], 10) | ||
var second = parseInt(matches[6], 10) | ||
const month = parseInt(matches[2], 10) - 1 | ||
const day = matches[3] | ||
const hour = parseInt(matches[4], 10) | ||
const minute = parseInt(matches[5], 10) | ||
const second = parseInt(matches[6], 10) | ||
var ms = matches[7] | ||
let ms = matches[7] | ||
ms = ms ? 1000 * parseFloat(ms) : 0 | ||
var date | ||
var offset = timeZoneOffset(isoDate) | ||
let date | ||
const offset = timeZoneOffset(isoDate) | ||
if (offset != null) { | ||
@@ -64,3 +64,3 @@ date = new Date(Date.UTC(year, month, day, hour, minute, second, ms)) | ||
function getDate (isoDate) { | ||
var matches = DATE.exec(isoDate) | ||
const matches = DATE.exec(isoDate) | ||
if (!matches) { | ||
@@ -70,4 +70,4 @@ return | ||
var year = parseInt(matches[1], 10) | ||
var isBC = !!matches[4] | ||
let year = parseInt(matches[1], 10) | ||
const isBC = !!matches[4] | ||
if (isBC) { | ||
@@ -77,6 +77,6 @@ year = bcYearToNegativeYear(year) | ||
var month = parseInt(matches[2], 10) - 1 | ||
var day = matches[3] | ||
const month = parseInt(matches[2], 10) - 1 | ||
const day = matches[3] | ||
// YYYY-MM-DD will be parsed as local time | ||
var date = new Date(year, month, day) | ||
const date = new Date(year, month, day) | ||
@@ -99,5 +99,5 @@ if (is0To99(year)) { | ||
var zone = TIME_ZONE.exec(isoDate.split(' ')[1]) | ||
const zone = TIME_ZONE.exec(isoDate.split(' ')[1]) | ||
if (!zone) return | ||
var type = zone[1] | ||
const type = zone[1] | ||
@@ -107,4 +107,4 @@ if (type === 'Z') { | ||
} | ||
var sign = type === '-' ? -1 : 1 | ||
var offset = parseInt(zone[2], 10) * 3600 + | ||
const sign = type === '-' ? -1 : 1 | ||
const offset = parseInt(zone[2], 10) * 3600 + | ||
parseInt(zone[3] || 0, 10) * 60 + | ||
@@ -111,0 +111,0 @@ parseInt(zone[4] || 0, 10) |
{ | ||
"name": "postgres-date", | ||
"main": "index.js", | ||
"version": "1.0.7", | ||
"version": "2.0.0", | ||
"description": "Postgres date column parser", | ||
@@ -14,3 +14,3 @@ "license": "MIT", | ||
"engines": { | ||
"node": ">=0.10.0" | ||
"node": ">=12" | ||
}, | ||
@@ -27,3 +27,3 @@ "scripts": { | ||
"devDependencies": { | ||
"standard": "^14.0.0", | ||
"standard": "^16.0.0", | ||
"tape": "^5.0.0" | ||
@@ -30,0 +30,0 @@ }, |
@@ -1,2 +0,2 @@ | ||
# postgres-date [![Build Status](https://travis-ci.org/bendrucker/postgres-date.svg?branch=master)](https://travis-ci.org/bendrucker/postgres-date) [![Greenkeeper badge](https://badges.greenkeeper.io/bendrucker/postgres-date.svg)](https://greenkeeper.io/) | ||
# postgres-date [![tests](https://github.com/bendrucker/postgres-date/workflows/tests/badge.svg)](https://github.com/bendrucker/postgres-date/actions?query=workflow%3Atests) | ||
@@ -16,10 +16,9 @@ > Postgres date output parser | ||
``` | ||
$ npm install --save postgres-date | ||
npm install --save postgres-date | ||
``` | ||
## Usage | ||
```js | ||
var parse = require('postgres-date') | ||
const parse = require('postgres-date') | ||
parse('2011-01-23 22:15:51Z') | ||
@@ -26,0 +25,0 @@ // => 2011-01-23T22:15:51.000Z |
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
5870
49