-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinitSetting.go
75 lines (67 loc) · 1.75 KB
/
initSetting.go
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package main
import (
"fmt"
"os"
"strconv"
"time"
"github.com/manifoldco/promptui"
)
func getDateReport() time.Time {
var currentMonthScrool int
var result time.Time
if len(os.Args) < 2 {
prompt := promptui.Select{
HideHelp: false,
Label: "Год",
Items: getSelectYearItems(),
}
_, year, err := prompt.Run()
checkError(err, "Ошибка")
currentMonth, _ := strconv.Atoi(time.Now().Format("01"))
currentMonth--
if currentMonth > 5 {
currentMonthScrool = currentMonth
} else {
currentMonthScrool = 0
}
prompt = promptui.Select{
HideHelp: false,
Label: "Месяц",
Items: getSelectMonthItems(),
}
_, month, err := prompt.RunCursorAt(currentMonth, currentMonthScrool)
checkError(err, "Ошибка")
t, _ := time.Parse("2006-January-02", fmt.Sprintf("%s-%s-01", year, month))
result = t
} else {
t, _ := time.Parse("2006-01", os.Args[1])
result = t
}
fmt.Printf("Поиск отчета за период %s \n", result)
return result;
}
func getSelectYearItems() []string {
var res []string
for i := 0; i < 3; i++ {
res = append(res, time.Now().AddDate(-i, 0, 0).Format("2006"))
}
return res;
}
func getSelectMonthItems() []string {
var res []string
for i := 1; i <= 12; i++ {
res = append(res, time.Date(2021, time.Month(i), 1, 0, 0, 0, 0, time.UTC).Format("January"))
}
return res;
}
func isNeedFutureTasks() bool {
prompt := promptui.Select{
HideSelected: true,
HideHelp: false,
Label: "Вы хотите получить список заданий будущего спринта",
Items: []string{"Да", "Нет"},
}
_, answer, err := prompt.Run()
checkError(err, "Ошибка")
return answer == "Да"
}