File size: 1,444 Bytes
a17d02d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
export const TIMER_WARNINGS = [30, 15, 10, 5, 1]

export const STATUS_CLASS = {
  current: 'q-dot q-dot-answered border-2 border-white',
  answered: 'q-dot q-dot-answered',
  'not-answered': 'q-dot q-dot-not-answered',
  'not-visited': 'q-dot q-dot-not-visited',
  marked: 'q-dot q-dot-marked',
  'answered-marked': 'q-dot q-dot-answered-marked',
}

export function formatTime(ms) {
  if (ms === null || ms === undefined || isNaN(ms)) return '--:--:--'
  const totalSecs = Math.max(0, Math.floor(ms / 1000))
  const h = Math.floor(totalSecs / 3600)
  const m = Math.floor((totalSecs % 3600) / 60)
  const s = totalSecs % 60
  return [h, m, s].map(n => String(n).padStart(2, '0')).join(':')
}

export function getQStatus(qId, currentQId, answers, marked) {
  if (qId === currentQId) return 'current'
  if (marked.has(qId) && answers[qId]) return 'answered-marked'
  if (marked.has(qId)) return 'marked'
  if (answers[qId]) return 'answered'
  return 'not-answered'
}

export function getEndTimeMs(startedAt, durationMinutes) {
  if (!startedAt || !durationMinutes) return null

  let startMs
  try {
    let str = String(startedAt).trim()
    if (!str.endsWith('Z') && !str.includes('+') && !/[0-9]-[0-9]{2}:[0-9]{2}$/.test(str)) {
      str = `${str}Z`
    }
    startMs = new Date(str).getTime()
    if (isNaN(startMs)) throw new Error('Invalid date')
  } catch {
    startMs = Date.now()
  }

  return startMs + durationMinutes * 60 * 1000
}