Пример #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
}
Пример #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
}
Пример #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
}
Пример #4
0
func TestPlusAnIntToNow(t *testing.T) {
	spec := gspec.New(t)
	filter := PlusFactory([]core.Value{intValue(61)})
	spec.Expect(filter("now", nil).(time.Time)).ToEqual(core.Now().Add(time.Minute * 61))
}