Skip to content

Commit

Permalink
period parse
Browse files Browse the repository at this point in the history
  • Loading branch information
drgrib committed Mar 18, 2017
1 parent cd44201 commit 484be5e
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 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"
"regexp"
"strconv"
"time"
)
Expand Down Expand Up @@ -61,7 +62,16 @@ func parseArgs(t, z string) (time.Duration, string) {
title := fmt.Sprintf("%v Timer", t)
return d, title
}
// parse as minute
// parse as time
pattern := `(\d+)(a|p)?`
r := regexp.MustCompile(pattern)
m := r.FindStringSubmatch(t)
period := m[2]
clock := m[1]
if period == "" {
fmt.Println("period ''", clock)
}
// if not time, parse as minute
minutes, err := strconv.Atoi(t)
if err != nil {
break
Expand Down Expand Up @@ -163,9 +173,9 @@ func (t *Timer) countDown() {
//////////////////////////////////////////////

func main() {
// pars
// parse
d, title := parseArgs(args.t, args.z)

return
// start timer
timer := Timer{title: title}
timer.start(d)
Expand Down

0 comments on commit 484be5e

Please sign in to comment.