mirror of
https://codeberg.org/timelimit/timelimit-server.git
synced 2025-10-05 19:42:39 +02:00
Add support for parent blocked times
This commit is contained in:
parent
32d278bdd5
commit
1969fe4042
15 changed files with 363 additions and 8 deletions
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue