func (s ScheduleItemView) GetItems(tin int64, weekday, start int64) ScheduleItems { var res ScheduleItems t := unixtime.Parse(tin).In(time.Now().Location()) s.Clean(t) _, w := t.ISOWeek() week := int64(w) pt := PeriodTypeByWeek(week) for _, v := range s.Items { if v.WeekDay == weekday && start == v.GetStartMin() && (v.PeriodType == pt || v.PeriodType == 0 || v.PeriodType == 3) { if v.PeriodType == 3 { res = ScheduleItems{v} return res } res = append(res, v) } } if len(res) == 0 { res = ScheduleItems{ScheduleItem{}} } return res }
func normTime(a int64) int64 { if a < 1440 { return a } t := unixtime.Parse(a).In(time.Now().Location()) t = t.In(time.Now().Location()) dur := t.Sub(now.New(t).BeginningOfDay()) //fmt.Println(t.Format("02.01.2006 15:04"), // now.New(t).BeginningOfDay().Format("02.01.2006 15:04")) return int64(dur.Minutes()) }
func PostersGetMonth(db *gorp.DbMap, t int64) (Posters, error) { tm := unixtime.Parse(t).In(time.Now().Location()) startMonth := now.New(tm).BeginningOfMonth().UnixNano() startMonth -= 24 * 60 * 60 endMonth := now.New(tm).EndOfMonth().UnixNano() endMonth += 24 * 60 * 60 var p Posters _, err := db.Select(&p, "select * from Poster where StartDate > ? and"+ " StartDate < ? and Deleted = 0 and Published = 1 order by StartDate", startMonth, endMonth) return p, err }
func (p Posters) Get(i, week int, mth time.Month) Posters { var res Posters for _, v := range p { t := unixtime.Parse(v.StartDate).In(time.Now().Location()) if t.Day() == i && mth == t.Month() { if week == 1 && i > 7 { continue } res = append(res, v) } } return res }
func TestTimeDuration(t *testing.T) { //unixnano := int64(1413781828752223110) //tn := time.Now() tr := time.Now() tn := time.Date(tr.Year(), tr.Month(), tr.Day(), 0, 510, tr.Second(), tr.Nanosecond(), tr.Location()) //unixtime.Parse(unixnano). //In(time.Now().Location()) mounths := 4 * time.Duration(30*24*time.Hour) td := tn.Add(90*time.Minute).Sub(tn) + mounths fmt.Println(td) fmt.Println(td.Nanoseconds()) utp := unixtime.Parse(tn.UnixNano()).In(tn.Location()).Add(td) fmt.Println(utp.Sub(tn).Nanoseconds()) fmt.Println(tn, "\n", timeTomMin(tn)) fmt.Println(utp, "\n", timeTomMin(utp)) }
func (s ScheduleItem) GetStartMin() int64 { h, m, _ := unixtime.Parse(s.Start).In(time.Now().Location()).Clock() return int64(h*60 + m) }