postgres-interval 4.0.1 → 4.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +17 -24
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -157,34 +157,27 @@ function readNextNum (interval) {
|
|
|
157
157
|
}
|
|
158
158
|
|
|
159
159
|
function parseMillisecond (interval) {
|
|
160
|
+
const previousPosition = position.value
|
|
160
161
|
const currentValue = readNextNum(interval)
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
if (currentValue < 100000) {
|
|
179
|
-
return currentValue / 100
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
if (currentValue < 1000000) {
|
|
183
|
-
return currentValue / 1000
|
|
162
|
+
const valueStringLength = position.value - previousPosition
|
|
163
|
+
|
|
164
|
+
switch (valueStringLength) {
|
|
165
|
+
case 1:
|
|
166
|
+
return currentValue * 100
|
|
167
|
+
case 2:
|
|
168
|
+
return currentValue * 10
|
|
169
|
+
case 3:
|
|
170
|
+
return currentValue
|
|
171
|
+
case 4:
|
|
172
|
+
return currentValue / 10
|
|
173
|
+
case 5:
|
|
174
|
+
return currentValue / 100
|
|
175
|
+
case 6:
|
|
176
|
+
return currentValue / 1000
|
|
184
177
|
}
|
|
185
178
|
|
|
186
179
|
// slow path
|
|
187
|
-
const remainder =
|
|
180
|
+
const remainder = valueStringLength - 3
|
|
188
181
|
return currentValue / Math.pow(10, remainder)
|
|
189
182
|
}
|
|
190
183
|
|