Socket
Socket
Sign inDemoInstall

postgres-date

Package Overview
Dependencies
0
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.0.3 to 1.0.4

58

index.js
'use strict'
var DATE_TIME = /(\d{1,})-(\d{2})-(\d{2}) (\d{2}):(\d{2}):(\d{2})(\.\d{1,})?/
var DATE = /^(\d{1,})-(\d{2})-(\d{2})$/
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 BC = /BC$/
var INFINITY = /^-?infinity$/

@@ -18,11 +17,10 @@

// Force YYYY-MM-DD dates to be parsed as local time
return DATE.test(isoDate) ?
getDate(isoDate) :
null
return getDate(isoDate) || null
}
var isBC = BC.test(isoDate)
var isBC = !!matches[8]
var year = parseInt(matches[1], 10)
var isFirstCentury = year > 0 && year < 100
year = (isBC ? '-' : '') + year
if (isBC) {
year = bcYearToNegativeYear(year)
}

@@ -41,10 +39,17 @@ var month = parseInt(matches[2], 10) - 1

if (offset != null) {
var utc = Date.UTC(year, month, day, hour, minute, second, ms)
date = new Date(utc - offset)
date = new Date(Date.UTC(year, month, day, hour, minute, second, ms))
// Account for years from 0 to 99 being interpreted as 1900-1999
// by Date.UTC / the multi-argument form of the Date constructor
if (is0To99(year)) {
date.setUTCFullYear(year)
}
date.setTime(date.getTime() - offset)
} else {
date = new Date(year, month, day, hour, minute, second, ms)
}
if (isFirstCentury) {
date.setUTCFullYear(year)
if (is0To99(year)) {
date.setFullYear(year)
}
}

@@ -57,3 +62,12 @@

var matches = DATE.exec(isoDate)
if (!matches) {
return
}
var year = parseInt(matches[1], 10)
var isBC = !!matches[4]
if (isBC) {
year = bcYearToNegativeYear(year)
}
var month = parseInt(matches[2], 10) - 1

@@ -63,3 +77,7 @@ var day = matches[3]

var date = new Date(year, month, day)
date.setFullYear(year)
if (is0To99(year)) {
date.setFullYear(year)
}
return date

@@ -87,1 +105,11 @@ }

}
function bcYearToNegativeYear (year) {
// Account for numerical difference between representations of BC years
// See: https://github.com/bendrucker/postgres-date/issues/5
return -(year - 1)
}
function is0To99 (num) {
return num >= 0 && num < 100
}
{
"name": "postgres-date",
"main": "index.js",
"version": "1.0.3",
"version": "1.0.4",
"description": "Postgres date column parser",

@@ -27,3 +27,3 @@ "license": "MIT",

"tape": "^4.0.0",
"standard": "^4.0.0"
"standard": "^12.0.1"
},

@@ -30,0 +30,0 @@ "files": [

@@ -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)
# 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/)

@@ -3,0 +3,0 @@ > Postgres date column parser

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc