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 (s *Store) NeedFlush(siteId int64) (bool, error) { lh, e := s.LastFlush(siteId) if e != nil { return false, e } // flush counters if new day if lh.Before(now.BeginningOfDay()) { return true, nil } return false, nil }
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) }
func (post *Post) HasEver3PostInLast24Hours() bool { rows, err := gest.db.Query("Select create_at from post where user_id=$1 order by create_at desc limit 3", post.UserId) LogFatalError(err) var i = 0 for rows.Next() { var createDate string rows.Scan(&createDate) layout := "2006-01-02 15:04:05" timepost, err := time.Parse(layout, createDate) LogFatalError(err) beginday := now.BeginningOfDay() if timepost.After(beginday) { i++ } } if i == 3 { return true } return false }