Skip to content

Commit

Permalink
period increment
Browse files Browse the repository at this point in the history
  • Loading branch information
drgrib committed Mar 18, 2017
1 parent fb9cd23 commit a8f7b3c
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions ttimer.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func parseClock(clock string) (int, int, error) {
return hour, 0, nil
}

func parseAsTime(t string, z string) (time.Duration, error) {
func parseTime(t string, z string) (time.Duration, error) {
// parameterized location due to not all platforms supporting local detection
loc, err := time.LoadLocation(z)
zero := time.Duration(0)
Expand Down Expand Up @@ -109,6 +109,14 @@ func parseAsTime(t string, z string) (time.Duration, error) {
for endTime.Before(now) {
endTime = endTime.Add(12 * time.Hour)
}
// final increment if wrong period
if period == "a" && endTime.Hour() >= 12 {
endTime = endTime.Add(12 * time.Hour)
}
if period == "p" && endTime.Hour() < 12 {
endTime = endTime.Add(12 * time.Hour)
}
// calculate the duration
d := endTime.Sub(now)
return d, nil
}
Expand All @@ -132,8 +140,7 @@ func parseArgs(t string, z string) (time.Duration, string) {
return d, title
}
// parse as time
// timeVal, err := parseAsTime(t, z)
d, err = parseAsTime(t, z)
d, err = parseTime(t, z)
if err == nil {
title := fmt.Sprintf("%v Timer", t)
return d, title
Expand Down

0 comments on commit a8f7b3c

Please sign in to comment.