@@ -8,9 +8,9 @@ function PostgresInterval (raw) {
8
8
}
9
9
Object . assign ( this , parse ( raw ) )
10
10
}
11
- var properties = [ 'seconds' , 'minutes' , 'hours' , 'days' , 'months' , 'years' ]
11
+ const properties = [ 'seconds' , 'minutes' , 'hours' , 'days' , 'months' , 'years' ]
12
12
PostgresInterval . prototype . toPostgres = function ( ) {
13
- var filtered = properties . filter ( this . hasOwnProperty , this )
13
+ const filtered = properties . filter ( this . hasOwnProperty , this )
14
14
15
15
// In addition to `properties`, we need to account for fractions of seconds.
16
16
if ( this . milliseconds && filtered . indexOf ( 'seconds' ) < 0 ) {
@@ -20,7 +20,7 @@ PostgresInterval.prototype.toPostgres = function () {
20
20
if ( filtered . length === 0 ) return '0'
21
21
return filtered
22
22
. map ( function ( property ) {
23
- var value = this [ property ] || 0
23
+ let value = this [ property ] || 0
24
24
25
25
// Account for fractional part of seconds,
26
26
// remove trailing zeroes.
@@ -33,30 +33,30 @@ PostgresInterval.prototype.toPostgres = function () {
33
33
. join ( ' ' )
34
34
}
35
35
36
- var propertiesISOEquivalent = {
36
+ const propertiesISOEquivalent = {
37
37
years : 'Y' ,
38
38
months : 'M' ,
39
39
days : 'D' ,
40
40
hours : 'H' ,
41
41
minutes : 'M' ,
42
42
seconds : 'S'
43
43
}
44
- var dateProperties = [ 'years' , 'months' , 'days' ]
45
- var timeProperties = [ 'hours' , 'minutes' , 'seconds' ]
44
+ const dateProperties = [ 'years' , 'months' , 'days' ]
45
+ const timeProperties = [ 'hours' , 'minutes' , 'seconds' ]
46
46
// according to ISO 8601
47
47
PostgresInterval . prototype . toISOString = PostgresInterval . prototype . toISO = function ( ) {
48
- var datePart = dateProperties
48
+ const datePart = dateProperties
49
49
. map ( buildProperty , this )
50
50
. join ( '' )
51
51
52
- var timePart = timeProperties
52
+ const timePart = timeProperties
53
53
. map ( buildProperty , this )
54
54
. join ( '' )
55
55
56
56
return 'P' + datePart + 'T' + timePart
57
57
58
58
function buildProperty ( property ) {
59
- var value = this [ property ] || 0
59
+ let value = this [ property ] || 0
60
60
61
61
// Account for fractional part of seconds,
62
62
// remove trailing zeroes.
@@ -68,18 +68,18 @@ PostgresInterval.prototype.toISOString = PostgresInterval.prototype.toISO = func
68
68
}
69
69
}
70
70
71
- var NUMBER = '([+-]?\\d+)'
72
- var YEAR = NUMBER + '\\s+years?'
73
- var MONTH = NUMBER + '\\s+mons?'
74
- var DAY = NUMBER + '\\s+days?'
75
- var TIME = '([+-])?([\\d]*):(\\d\\d):(\\d\\d)\\.?(\\d{1,6})?'
76
- var INTERVAL = new RegExp ( [ YEAR , MONTH , DAY , TIME ] . map ( function ( regexString ) {
71
+ const NUMBER = '([+-]?\\d+)'
72
+ const YEAR = NUMBER + '\\s+years?'
73
+ const MONTH = NUMBER + '\\s+mons?'
74
+ const DAY = NUMBER + '\\s+days?'
75
+ const TIME = '([+-])?([\\d]*):(\\d\\d):(\\d\\d)\\.?(\\d{1,6})?'
76
+ const INTERVAL = new RegExp ( [ YEAR , MONTH , DAY , TIME ] . map ( function ( regexString ) {
77
77
return '(' + regexString + ')?'
78
78
} )
79
79
. join ( '\\s*' ) )
80
80
81
81
// Positions of values in regex match
82
- var positions = {
82
+ const positions = {
83
83
years : 2 ,
84
84
months : 4 ,
85
85
days : 6 ,
@@ -89,22 +89,22 @@ var positions = {
89
89
milliseconds : 12
90
90
}
91
91
// We can use negative time
92
- var negatives = [ 'hours' , 'minutes' , 'seconds' , 'milliseconds' ]
92
+ const negatives = [ 'hours' , 'minutes' , 'seconds' , 'milliseconds' ]
93
93
94
94
function parseMilliseconds ( fraction ) {
95
95
// add omitted zeroes
96
- var microseconds = fraction + '000000' . slice ( fraction . length )
96
+ const microseconds = fraction + '000000' . slice ( fraction . length )
97
97
return parseInt ( microseconds , 10 ) / 1000
98
98
}
99
99
100
100
function parse ( interval ) {
101
101
if ( ! interval ) return { }
102
- var matches = INTERVAL . exec ( interval )
103
- var isNegative = matches [ 8 ] === '-'
102
+ const matches = INTERVAL . exec ( interval )
103
+ const isNegative = matches [ 8 ] === '-'
104
104
return Object . keys ( positions )
105
105
. reduce ( function ( parsed , property ) {
106
- var position = positions [ property ]
107
- var value = matches [ position ]
106
+ const position = positions [ property ]
107
+ let value = matches [ position ]
108
108
// no empty string
109
109
if ( ! value ) return parsed
110
110
// milliseconds are actually microseconds (up to 6 digits)
0 commit comments