postgres-date
Advanced tools
Comparing version 1.0.2 to 1.0.3
19
index.js
@@ -5,3 +5,3 @@ 'use strict' | ||
var DATE = /^(\d{1,})-(\d{2})-(\d{2})$/ | ||
var TIME_ZONE = /([Z|+\-])(\d{2})?:?(\d{2})?:?(\d{2})?/ | ||
var TIME_ZONE = /([Z+-])(\d{2})?:?(\d{2})?:?(\d{2})?/ | ||
var BC = /BC$/ | ||
@@ -20,3 +20,3 @@ var INFINITY = /^-?infinity$/ | ||
return DATE.test(isoDate) ? | ||
new Date(isoDate + 'T00:00:00') : | ||
getDate(isoDate) : | ||
null | ||
@@ -55,2 +55,13 @@ } | ||
function getDate (isoDate) { | ||
var matches = DATE.exec(isoDate) | ||
var year = parseInt(matches[1], 10) | ||
var month = parseInt(matches[2], 10) - 1 | ||
var day = matches[3] | ||
// YYYY-MM-DD will be parsed as local time | ||
var date = new Date(year, month, day) | ||
date.setFullYear(year) | ||
return date | ||
} | ||
// match timezones: | ||
@@ -60,3 +71,2 @@ // Z (UTC) | ||
// +06:30 | ||
var types = ['Z', '+', '-'] | ||
function timeZoneOffset (isoDate) { | ||
@@ -67,5 +77,2 @@ var zone = TIME_ZONE.exec(isoDate.split(' ')[1]) | ||
if (!~types.indexOf(type)) { | ||
throw new Error('Unidentified time zone part: ' + type) | ||
} | ||
if (type === 'Z') { | ||
@@ -72,0 +79,0 @@ return 0 |
{ | ||
"name": "postgres-date", | ||
"main": "index.js", | ||
"version": "1.0.2", | ||
"version": "1.0.3", | ||
"description": "Postgres date column parser", | ||
@@ -6,0 +6,0 @@ "license": "MIT", |
4269
69