--until option
parent
de9f92da1c
commit
f9f8340056
22
main.go
22
main.go
|
|
@ -5,6 +5,8 @@ import (
|
|||
"flag"
|
||||
"fmt"
|
||||
"local/logger"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/eiannone/keyboard"
|
||||
|
|
@ -24,6 +26,7 @@ func main() {
|
|||
var repeat bool
|
||||
var invert bool
|
||||
var eta bool
|
||||
var until string
|
||||
|
||||
flag.BoolVar(&repeat, "repeat", true, "Whether to repeat the timer on complete")
|
||||
flag.BoolVar(&invert, "stopwatch", false, "Use as a stopwatch")
|
||||
|
|
@ -32,8 +35,27 @@ func main() {
|
|||
flag.StringVar(&alertMessage, "msg", "Timer up", "Message to display on timer expiration")
|
||||
flag.StringVar(&interval, "interval", "500ms", "Interval duration")
|
||||
flag.BoolVar(&eta, "eta", false, "Whether to display the ending time")
|
||||
flag.StringVar(&until, "until", "", "Overload to make a non-repeating timer until given time as 23:59")
|
||||
flag.Parse()
|
||||
|
||||
if until != "" {
|
||||
repeat = false
|
||||
offset = "0m"
|
||||
now := time.Now()
|
||||
targetHourStr := strings.Split(until, ":")[0]
|
||||
targetMinStr := strings.Split(until, ":")[1]
|
||||
hour, err := strconv.Atoi(targetHourStr)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
min, err := strconv.Atoi(targetMinStr)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
thenTime := time.Date(now.Year(), now.Month(), now.Day(), hour, min, 0, 0, now.Location())
|
||||
duration = thenTime.Sub(now).String()
|
||||
}
|
||||
|
||||
tickerInterval, err := time.ParseDuration(interval)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
|
|
|
|||
Loading…
Reference in New Issue