Beispiel #1
0
func timeFromString(s string) (time.Time, bool) {
	if s == "now" || s == "today" {
		return core.Now(), true
	}
	t, err := time.Parse("2006-01-02 15:04:05 -0700", s)
	if err != nil {
		return zeroTime, false
	}
	return t, true
}
Beispiel #2
0
func stringPlusInt(s string, plus int) interface{} {
	if s == "now" || s == "today" {
		return core.Now().Add(time.Minute * time.Duration(plus))
	}
	if i, err := strconv.Atoi(s); err == nil {
		return i + plus
	}
	if f, err := strconv.ParseFloat(s, 64); err == nil {
		return f + float64(plus)
	}
	return s
}
Beispiel #3
0
func inputToTime(input interface{}) (time.Time, bool) {
	switch typed := input.(type) {
	case time.Time:
		return typed, true
	case string:
		return timeFromString(typed)
	case []byte:
		return timeFromString(string(typed))
	}
	if n, ok := core.ToInt(input); ok {
		return core.Now().Add(time.Minute * time.Duration(n)), true
	}
	return zeroTime, false
}