MCPcopy Create free account
hub / github.com/bendrucker/postgres-interval / parse

Function parse

index.js:203–263  ·  view source on GitHub ↗
(instance, interval)

Source from the content-addressed store, hash-verified

201}
202
203function parse (instance, interval) {
204 if (!interval) {
205 return
206 }
207
208 position.value = 0
209
210 let currentValue
211 let nextNegative = 1
212
213 while (position.value < interval.length) {
214 const char = interval[position.value]
215
216 if (char === '-') {
217 nextNegative = -1
218 position.value++
219 continue
220 } else if (!(char >= '0' && char <= '9')) {
221 position.value++
222 continue
223 } else {
224 currentValue = readNextNum(interval)
225
226 if (interval[position.value] === ':') {
227 instance.hours = currentValue ? nextNegative * currentValue : 0
228
229 position.value++
230 currentValue = readNextNum(interval)
231 instance.minutes = currentValue ? nextNegative * currentValue : 0
232
233 position.value++
234 currentValue = readNextNum(interval)
235 instance.seconds = currentValue ? nextNegative * currentValue : 0
236
237 if (interval[position.value] === '.') {
238 position.value++
239
240 currentValue = parseMillisecond(interval)
241 instance.milliseconds = currentValue ? nextNegative * currentValue : 0
242 }
243
244 return
245 }
246
247 // skip space
248 position.value++
249
250 const unit = interval[position.value]
251
252 if (unit === 'y') {
253 instance.years = currentValue ? nextNegative * currentValue : 0
254 } else if (unit === 'm') {
255 instance.months = currentValue ? nextNegative * currentValue : 0
256 } else if (unit === 'd') {
257 instance.days = currentValue ? nextNegative * currentValue : 0
258 }
259
260 nextNegative = 1

Callers 2

PostgresIntervalFunction · 0.85
index.jsFile · 0.85

Calls 2

readNextNumFunction · 0.85
parseMillisecondFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…