Skip to content

Commit 2013b03

Browse files
authored
Merge pull request #327 from dmur1/fix-ctftime-command-showing-times-in-utc-not-local-#315
use local not utc for times in ctftime command
2 parents 9149f27 + 8a4b599 commit 2013b03

File tree

1 file changed

+19
-7
lines changed

1 file changed

+19
-7
lines changed

commands/ctftime.go

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -105,24 +105,36 @@ func fetchInfo(ctfTimeUrl string, info *CTFTimeInfo) {
105105
}
106106

107107
func showInfo(info *CTFTimeInfo) {
108-
fmt.Printf(theme.ColorGray+"title: "+theme.ColorBlue+"%s"+theme.ColorReset+"\n", info.Title)
109-
110108
now := time.Now()
111109

112-
fmt.Printf(theme.ColorGray+"start: "+theme.ColorGreen+"%v "+theme.ColorGray+"finish: "+theme.ColorRed+"%v"+theme.ColorReset+"\n", info.Start, info.Finish)
113-
114110
started := info.Start.Before(now)
115111
finished := info.Finish.Before(now)
116112
ongoing := started && !finished
117113

114+
fmt.Printf(theme.ColorGray+"title: "+theme.ColorBlue+"%s"+theme.ColorReset+" ", info.Title)
115+
118116
if ongoing {
119117
fmt.Printf(theme.ColorGray+"time remaining: "+theme.ColorReset+"%v\n", info.Finish.Sub(now))
120118
} else if finished {
121119
fmt.Printf(theme.ColorGray+"time since finish: "+theme.ColorReset+"%v\n", info.Finish.Sub(now))
122120
} else {
123-
fmt.Printf(theme.ColorGray+"time to start: "+theme.ColorReset+"%v\n", info.Start.Sub(now))
124-
fmt.Printf(theme.ColorGray+"time to finish: "+theme.ColorReset+"%v\n", info.Finish.Sub(now))
121+
delta := info.Start.Sub(now)
122+
123+
hours := int(delta.Hours())
124+
mins := int(delta.Minutes())
125+
seconds := int(delta.Seconds())
126+
127+
if hours > 0 {
128+
fmt.Printf(theme.ColorGray+"starts in "+theme.ColorPurple+"~%v"+theme.ColorGray+" hours\n", hours)
129+
} else if mins > 0 {
130+
fmt.Printf(theme.ColorGray+"starts in "+theme.ColorPurple+"~%v"+theme.ColorGray+" mins\n", mins)
131+
} else {
132+
fmt.Printf(theme.ColorGray+"starts in "+theme.ColorPurple+"~%v"+theme.ColorGray+" seconds\n", seconds)
133+
}
125134
}
135+
136+
fmt.Printf(theme.ColorGray+"start: "+theme.ColorGreen+"%v"+theme.ColorReset+"\n", info.Start.Local())
137+
fmt.Printf(theme.ColorGray+"finish: "+theme.ColorRed+"%v"+theme.ColorReset+"\n", info.Finish.Local())
126138
}
127139

128140
func CtfTime(args []string) {
@@ -161,7 +173,7 @@ func CtfTime(args []string) {
161173
fmt.Printf("\r")
162174

163175
for idx, ctfTimeUrl := range config.CtfTimeUrls {
164-
fmt.Printf(theme.ColorGray+"url: "+theme.ColorReset+"%v"+theme.ColorReset+"\n", ctfTimeUrl)
176+
fmt.Printf(theme.ColorGray+"url: "+theme.ColorCyan+theme.StartUnderline+"%v"+theme.ColorReset+theme.StopUnderline+"\n", ctfTimeUrl)
165177

166178
if strings.Contains(ctfTimeUrl, "ctftime.org") {
167179
showInfo(&infos[idx])

0 commit comments

Comments
 (0)