-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathfreedomcountdown.go
58 lines (48 loc) · 1.13 KB
/
freedomcountdown.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
package main
import (
"flag"
"fmt"
"os"
"time"
)
func main() {
deadline := flag.String("deadline", "2021-03-01T00:00:00-05:00", "The deadline for the countdown timer in RFC3339 format (e.g. 2019-12-25T15:00:00+01:00)")
name := flag.String("name", "Ulises", "The person getting free")
flag.Parse()
v, err := time.Parse(time.RFC3339, *deadline)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
for range time.Tick(1 * time.Second) {
timeRemaining := getTimeRemaining(v)
if timeRemaining.t <= 0 {
fmt.Printf("%s's Free!", *name)
break
}
fmt.Printf("\r%d Days, %d Hours, %d Minutes, and %d Seconds until %s's Free", timeRemaining.d, timeRemaining.h, timeRemaining.m, timeRemaining.s, *name)
}
}
type countdown struct {
t int
d int
h int
m int
s int
}
func getTimeRemaining(t time.Time) countdown {
currentTime := time.Now()
difference := t.Sub(currentTime)
total := int(difference.Seconds())
days := int(total / (60 * 60 * 24))
hours := int(total / (60 * 60) % 24)
minutes := int(total/60) % 60
seconds := int(total % 60)
return countdown{
t: total,
d: days,
h: hours,
m: minutes,
s: seconds,
}
}