trackCmd: Parse dates with now

This commit is contained in:
Cat /dev/Nulo 2022-09-04 21:40:00 -03:00
parent 83790d0f18
commit fc1aa49ea4

View file

@ -10,20 +10,20 @@ import (
"time" "time"
"math" "math"
"errors" "errors"
"github.com/jinzhu/now"
) )
const ( const (
TFAbsTwelveHour int = 0 TFAbsTwelveHour int = 0
TFAbsTwentyfourHour int = 1 TFRelHourMinute int = 1
TFRelHourMinute int = 2 TFRelHourFraction int = 2
TFRelHourFraction int = 3
) )
func TimeFormats() []string { func TimeFormats() []string {
return []string{ return []string{
`^\d{1,2}:\d{1,2}(am|pm)$`, // Absolute twelve hour format `^\d{1,2}:\d{1,2}(am|pm)$`, // Absolute twelve hour format
`^\d{1,2}:\d{1,2}$`, // Absolute twenty four hour format
`^([+-])(\d{1,2}):(\d{1,2})$`, // Relative hour:minute format `^([+-])(\d{1,2}):(\d{1,2})$`, // Relative hour:minute format
`^([+-])(\d{1,2})\.(\d{1,2})$`, // Relative hour.fraction format `^([+-])(\d{1,2})\.(\d{1,2})$`, // Relative hour.fraction format
} }
@ -98,14 +98,10 @@ func ParseTime(timeStr string) (time.Time, error) {
tadj, err := time.Parse("3:04pm", timeStr) tadj, err := time.Parse("3:04pm", timeStr)
tnew := time.Date(t.Year(), t.Month(), t.Day(), tadj.Hour(), tadj.Minute(), t.Second(), t.Nanosecond(), t.Location()) tnew := time.Date(t.Year(), t.Month(), t.Day(), tadj.Hour(), tadj.Minute(), t.Second(), t.Nanosecond(), t.Location())
return tnew, err return tnew, err
case TFAbsTwentyfourHour:
tadj, err := time.Parse("15:04", timeStr)
tnew := time.Date(t.Year(), t.Month(), t.Day(), tadj.Hour(), tadj.Minute(), t.Second(), t.Nanosecond(), t.Location())
return tnew, err
case TFRelHourMinute, TFRelHourFraction: case TFRelHourMinute, TFRelHourFraction:
return RelToTime(timeStr, tfId) return RelToTime(timeStr, tfId)
default: default:
return time.Now(), errors.New("could not match passed time") return now.Parse(timeStr)
} }
} }