func (this *TimeFrame) parsePreviousNUnits(n int, units string) bool { switch units { case "minutes": this.Start = now.BeginningOfMinute().Add(time.Duration(-n) * time.Minute) this.End = now.BeginningOfMinute() case "hours": this.Start = now.BeginningOfHour().Add(time.Duration(-n) * time.Hour) this.End = now.BeginningOfHour() case "days": this.Start = now.BeginningOfDay().AddDate(0, 0, -n) this.End = now.BeginningOfDay() case "weeks": this.Start = now.BeginningOfWeek().AddDate(0, 0, -n*7) this.End = now.BeginningOfWeek() case "months": this.Start = now.BeginningOfMonth().AddDate(0, -n, 0) this.End = now.BeginningOfMonth() case "years": this.Start = now.BeginningOfYear().AddDate(-n, 0, 0) this.End = now.BeginningOfYear() default: return false } return true }
func (this *TimeFrame) parseRelUnits(rel string, units string) bool { if rel != "this" { return false } switch units { case "minute": this.Start = now.BeginningOfMinute() case "hour": this.Start = now.BeginningOfHour() case "day": this.Start = now.BeginningOfDay() case "week": this.Start = now.BeginningOfWeek() case "month": this.Start = now.BeginningOfMonth() case "year": this.Start = now.BeginningOfYear() default: return false } this.End = time.Now() return true }
func GetDateRef(pattern string) (time.Time, error) { var dateRef time.Time now.FirstDayMonday = true switch pattern { case "BeginningOfMinute": return now.BeginningOfMinute(), nil case "BeginningOfHour": return now.BeginningOfHour(), nil case "BeginningOfDay": return now.BeginningOfDay(), nil case "BeginningOfWeek": return now.BeginningOfWeek(), nil case "BeginningOfMonth": return now.BeginningOfMonth(), nil case "BeginningOfQuarter": return now.BeginningOfQuarter(), nil case "BeginningOfYear": return now.BeginningOfYear(), nil } return dateRef, fmt.Errorf("Invalid pattern:%s", pattern) }