--until option

master
Bel LaPointe 2018-06-27 14:17:07 -06:00
parent de9f92da1c
commit f9f8340056
1 changed files with 22 additions and 0 deletions

22
main.go
View File

@ -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)