Skip to content

Commit

Permalink
minute parse
Browse files Browse the repository at this point in the history
  • Loading branch information
drgrib committed Mar 18, 2017
1 parent bb0e913 commit ab6dc28
Showing 1 changed file with 23 additions and 5 deletions.
28 changes: 23 additions & 5 deletions ttimer.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
ui "github.com/gizak/termui"
"math"
"strconv"
"time"
)

Expand All @@ -20,7 +21,7 @@ var args struct {

func init() {
flag.StringVar(
&args.t, "t", "100", "time string")
&args.t, "t", "1", "time string")
flag.StringVar(
&args.z, "z", "-0800", "timezone string")
flag.BoolVar(
Expand All @@ -29,15 +30,32 @@ func init() {
}

//////////////////////////////////////////////
/// functions
/// util
//////////////////////////////////////////////

func panicErr(err error) {
func mustBeNil(err error) {
if err != nil {
panic(err)
}
}

//////////////////////////////////////////////
/// argsToDuration
//////////////////////////////////////////////

func argsToDuration(t, z string) time.Duration {
var d time.Duration
d = time.Duration(6 * time.Second)
if len(t) == 1 {
// simple minute timer
minutes, err := strconv.Atoi(t)
mustBeNil(err)
d = time.Duration(minutes) * time.Minute
}
fmt.Println(len(z))
return d
}

//////////////////////////////////////////////
/// Timer
//////////////////////////////////////////////
Expand Down Expand Up @@ -68,7 +86,7 @@ func (t *Timer) update() {
func (t *Timer) countDown() {
// init and close
err := ui.Init()
panicErr(err)
mustBeNil(err)
defer ui.Close()

// init cell
Expand Down Expand Up @@ -123,10 +141,10 @@ func (t *Timer) countDown() {
//////////////////////////////////////////////

func main() {
d := argsToDuration(args.t, args.z)

// start timer
timer := Timer{title: "Timer"}
d := time.Duration(6 * time.Second)
timer.start(d)

// run UI
Expand Down

0 comments on commit ab6dc28

Please sign in to comment.