Add support for parent blocked times

This commit is contained in:
Jonas Lochmann 2019-08-19 00:00:00 +00:00
parent 32d278bdd5
commit 1969fe4042
No known key found for this signature in database
GPG key ID: 8B8C9AEE10FA5B36
15 changed files with 363 additions and 8 deletions

View file

@ -15,7 +15,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
import { split } from 'lodash'
import { range, split } from 'lodash'
export const serializedBitmaskRegex = /^(\d*,\d*(,\d*,\d*)*)?$/
@ -52,3 +52,23 @@ export const validateBitmask = (bitmask: string, maxLength: number) => {
previousValue = item
})
}
export const validateAndParseBitmask = (bitmask: string, maxLength: number) => {
validateBitmask(bitmask, maxLength)
const result = range(0, maxLength).map((_) => false)
const splitpoints = split(bitmask, ',').map((item) => parseInt(item, 10))
let i = 0
while (i < splitpoints.length) {
const start = splitpoints[i++]
const end = splitpoints[i++]
for (let j = start; j < end; j++) {
result[j] = true
}
}
return result
}