formkit/tempo

validOffset is too permissive

mdbudnick opened this issue · 0 comments

The current validOffset code allows up to 39 hours and 69 minutes e.g. '+3969'. This is too wide, and makes the current validation incorrect.

The offsets being validated are Tempo defined offsets According to the documentation, these should be ISO 8601 compatible, and, according to the list of UTC offsets one only needs to go up to 15 hours and 45 minutes.

Current 'wide' validOffset implementation

export function validOffset(offset: striang) {
  const valid = /^([+-])[0-3][0-9][0-6][0-9]$/.test(offset)
  if (!valid) throw new Error(`Invalid offset: ${offset}`)
  return offset
}