aboutsummaryrefslogtreecommitdiff
path: root/go/draftsim/common/deadline.go
blob: 9a8ce9d8a2c68d05626e35c458e0c28b05bf533e (plain)
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
package common

import (
	"strings"
	"time"
)

type DeadlineFunc func(cards int) time.Time

func genFixedDeadline(timeout int) DeadlineFunc {
	return func(int) time.Time {
		return time.Now().Add(time.Duration(timeout)*time.Second)
	}
}

func genDynamicDeadline(perCard int) DeadlineFunc {
	return func(cards int) time.Time {
		return time.Now().Add(time.Duration(perCard * cards) * time.Second)
	}
}

// GenDeadline returns a function returning a deadline from a description string.
func GenDeadline(desc string) (DeadlineFunc, error) {
	if strings.Contains(desc, "x") {
		perCard := 5
		return genDynamicDeadline(perCard), nil
	} else {
		return genFixedDeadline(30), nil
	}
}