当前位置: 首页>>代码示例>>Golang>>正文


Golang Time.Before方法代码示例

本文整理汇总了Golang中Time.Time.Before方法的典型用法代码示例。如果您正苦于以下问题:Golang Time.Before方法的具体用法?Golang Time.Before怎么用?Golang Time.Before使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Time.Time的用法示例。


在下文中一共展示了Time.Before方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: skews

// skews returns clock skew information for all writers recorded in the
// document, given that the document was read between the supplied local
// times. It will return an error if the clock document is not valid, or
// if the times don't make sense.
func (doc clockDoc) skews(beginning, end time.Time) (map[string]Skew, error) {
	if err := doc.validate(); err != nil {
		return nil, errors.Trace(err)
	}
	// beginning is expected to be earlier than end.
	// If it isn't, it could be ntp rolling the clock back slowly, so we add
	// a little wiggle room here.
	if end.Before(beginning) {
		// A later time, subtract an earlier time will give a positive duration.
		difference := beginning.Sub(end)
		if difference > 10*time.Millisecond {
			return nil, errors.Errorf("end of read window preceded beginning (%s)", difference)

		}
		beginning = end
	}
	skews := make(map[string]Skew)
	for writer, written := range doc.Writers {
		skews[writer] = Skew{
			LastWrite: toTime(written),
			Beginning: beginning,
			End:       end,
		}
	}
	return skews, nil
}
开发者ID:felicianotech,项目名称:juju,代码行数:30,代码来源:schema.go

示例2: Update

func (r *Rrd) Update(timestamp time.Time, values []string) error {
	if timestamp.Before(r.LastUpdate) {
		return errors.Errorf("illegal attempt to update using time %s when last update time is %s (minimum one second step)", timestamp.String(), r.LastUpdate.String())
	}

	elapsed := r.calculateElapsedSteps(timestamp)

	newPdps, err := r.calculatePdpPreps(elapsed.Interval, values)
	if err != nil {
		return err
	}

	if elapsed.Steps == 0 {
		r.simpleUpdate(newPdps, elapsed.Interval)
	} else {
		pdpTemp := r.processAllPdp(newPdps, elapsed)
		rraStepCounts := r.updateAllCdpPreps(pdpTemp, elapsed)
		r.updateAberrantCdps(pdpTemp, elapsed)
		r.writeToRras(rraStepCounts)
		for i, rra := range r.Rras {
			if err := r.Store.StoreRraParams(i, rra); err != nil {
				return err
			}
		}
	}

	return r.writeChanges(timestamp)
}
开发者ID:untoldwind,项目名称:gorrd,代码行数:28,代码来源:rrd_update.go

示例3: IsActiveAt

// Returns wheter the Timing is active at the specified time
func (rit *RITiming) IsActiveAt(t time.Time) bool {
	// check for years
	if len(rit.Years) > 0 && !rit.Years.Contains(t.Year()) {
		return false
	}
	// check for months
	if len(rit.Months) > 0 && !rit.Months.Contains(t.Month()) {
		return false
	}
	// check for month days
	if len(rit.MonthDays) > 0 && !rit.MonthDays.Contains(t.Day()) {
		return false
	}
	// check for weekdays
	if len(rit.WeekDays) > 0 && !rit.WeekDays.Contains(t.Weekday()) {
		return false
	}
	//log.Print("Time: ", t)

	//log.Print("Left Margin: ", rit.getLeftMargin(t))
	// check for start hour
	if t.Before(rit.getLeftMargin(t)) {
		return false
	}

	//log.Print("Right Margin: ", rit.getRightMargin(t))
	// check for end hour
	if t.After(rit.getRightMargin(t)) {
		return false
	}
	return true
}
开发者ID:bhepp,项目名称:cgrates,代码行数:33,代码来源:rateinterval.go

示例4: addPreviousEvent

// Locate the event in this object that is unrelated to the alert event,
// and is closest to it based on the timestamp
func (ad *alertDetailsBranch) addPreviousEvent(o *object, branchID string) (err error) {
	defer func() {
		if e := recover(); e != nil {
			err = fmt.Errorf("addPreviousEvent() -> %v", e)
		}
	}()

	var res *objectResult
	var latest time.Time
	for i := range o.Results {
		if o.Results[i].BranchID == branchID {
			continue
		} else if o.Results[i].CollapseBranch == branchID {
			continue
		}
		if latest.Before(o.Results[i].Timestamp) {
			res = &o.Results[i]
		}
	}
	if res == nil {
		return nil
	}

	ad.PrevLocality = res.Locality
	ad.PrevLatitude = res.Latitude
	ad.PrevLongitude = res.Longitude
	ad.PrevTimestamp = res.Timestamp
	ad.PrevDistance = kmBetweenTwoPoints(ad.Latitude, ad.Longitude,
		ad.PrevLatitude, ad.PrevLongitude)
	return nil
}
开发者ID:ameihm0912,项目名称:geomodel,代码行数:33,代码来源:object.go

示例5: ActiveAt

// ActiveAt says whether the given time is
// wihtin the schedule of this Day schedule.
func (d *Day) ActiveAt(t time.Time) bool {
	if loc, err := d.GetLocation(); loc != nil && err == nil {
		t = t.In(loc)
	}
	start, stop := d.Times(t)
	return t.After(start) && t.Before(stop)
}
开发者ID:CyCoreSystems,项目名称:ipc-schedule,代码行数:9,代码来源:day.go

示例6: advance

// advance cycles the buckets at each level until the latest bucket in
// each level can hold the time specified.
func (ts *timeSeries) advance(t time.Time) {
	if !t.After(ts.levels[0].end) {
		return
	}
	for i := 0; i < len(ts.levels); i++ {
		level := ts.levels[i]
		if !level.end.Before(t) {
			break
		}

		// If the time is sufficiently far, just clear the level and advance
		// directly.
		if !t.Before(level.end.Add(level.size * time.Duration(ts.numBuckets))) {
			for _, b := range level.buckets {
				ts.resetObservation(b)
			}
			level.end = time.Unix(0, (t.UnixNano()/level.size.Nanoseconds())*level.size.Nanoseconds())
		}

		for t.After(level.end) {
			level.end = level.end.Add(level.size)
			level.newest = level.oldest
			level.oldest = (level.oldest + 1) % ts.numBuckets
			ts.resetObservation(level.buckets[level.newest])
		}

		t = level.end
	}
}
开发者ID:2722,项目名称:lantern,代码行数:31,代码来源:timeseries.go

示例7: LoadPerf

func LoadPerf(fName string, since, until time.Time) ([]PerfLogEntry, error) {
	fIn, err := os.Open(fName)
	if err != nil {
		return nil, err
	}
	defer fIn.Close()

	dec := json.NewDecoder(fIn)
	var result []PerfLogEntry
	for {
		var entry PerfLogEntry
		err = dec.Decode(&entry)
		if err != nil {
			if strings.Contains(err.Error(), "EOF") {
				break
			} else {
				return nil, fmt.Errorf("Decode error: %v", err)
			}
		} else {
			if !since.Equal(time.Time{}) && since.After(entry.Timestamp) {
				continue
			}
			if !until.Equal(time.Time{}) && until.Before(entry.Timestamp) {
				continue
			}
			result = append(result, entry)
		}
	}
	return result, nil
}
开发者ID:mikhailborodin,项目名称:gopnik,代码行数:30,代码来源:loader.go

示例8: housekeep

func (rm *realManager) housekeep(start, end time.Time) {
	if !start.Before(end) {
		glog.Warningf("Wrong time provided to housekeep start:%s end: %s", start, end)
		return
	}

	select {
	case <-rm.housekeepSemaphoreChan:
		// ok, good to go

	case <-time.After(rm.housekeepTimeout):
		glog.Warningf("Spent too long waiting for housekeeping to start")
		return
	}

	go func(rm *realManager) {
		// should always give back the semaphore
		defer func() { rm.housekeepSemaphoreChan <- struct{}{} }()
		data := rm.source.ScrapeMetrics(start, end)

		for _, p := range rm.processors {
			newData, err := process(p, data)
			if err == nil {
				data = newData
			} else {
				glog.Errorf("Error in processor: %v", err)
				return
			}
		}

		// Export data to sinks
		rm.sink.ExportData(data)

	}(rm)
}
开发者ID:kubernetes,项目名称:heapster,代码行数:35,代码来源:manager.go

示例9: shouldRoll

// Determine whether we should roll the log file. Must be in lock already.
func (a *fileAppender) shouldRoll(tstamp time.Time) bool {
	if a.rollFrequency == RollNone {
		return false
	} else {
		return !tstamp.Before(a.nextRollTime)
	}
}
开发者ID:neocortical,项目名称:log5go,代码行数:8,代码来源:fileappender.go

示例10: SetStart

func (i *Interval) SetStart(t time.Time) error {
	if !t.Before(i.End()) {
		return errors.New("Start must be before end.")
	}
	i.StartTime = t
	return nil
}
开发者ID:jaffee,项目名称:sked,代码行数:7,代码来源:shift.go

示例11: launchWorker

func launchWorker(c *client.Client, w workload, timeout time.Duration,
	start chan struct{}, resch chan result) {

	<-start

	call := make(chan client.Response, len(w.enqs))
	reqStart := make(map[server.ReqID]time.Time)
	reqEnd := make(map[server.ReqID]time.Time)

	var minStart time.Time
	done := make(chan struct{})
	go func() {
		for i, e := range w.enqs {
			now := time.Now()
			if i == 0 {
				minStart = now
			}
			req, _ := c.GoEnQ(string(e.Queue), e.Body, call)
			reqStart[req] = now
		}
		close(done)
	}()

	res := result{
		// TODO(soheil): implement deques as well.
		size: uint64(len(w.enqs)), //+ len(w.deqs),
	}
	var to <-chan time.Time
	if timeout != 0 {
		to = time.After(timeout)
	}

loop:
	for i := 0; i < len(w.enqs); i++ {
		select {
		case response := <-call:
			if response.Error != nil {
				continue
			}
			reqEnd[response.ID] = time.Now()
			res.reqs++
		case <-to:
			break loop
		}
	}

	<-done

	var maxEnd time.Time
	for req, end := range reqEnd {
		if maxEnd.Before(end) {
			maxEnd = end
		}
		d := end.Sub(reqStart[req])
		res.enqDurs = append(res.enqDurs, d)
	}
	res.start = minStart
	res.end = maxEnd
	resch <- res
}
开发者ID:jyzhe,项目名称:beehive,代码行数:60,代码来源:bench.go

示例12: in

func in(date, start, end time.Time) bool {
	if date.Equal(start) || date.Equal(end) {
		return true
	}

	return date.After(start) && date.Before(end)
}
开发者ID:igungor,项目名称:ilber,代码行数:7,代码来源:holiday.go

示例13: GetQuery

func (reqs Requests) GetQuery() url.Values {
	query := make(url.Values)
	var from, until time.Time

	for _, r := range reqs {
		query.Add("target", r.Key)
		if from.IsZero() {
			from = r.From
		} else if from.After(r.From) {
			from = r.From
		}
		if until.IsZero() {
			until = r.Until
		} else if until.Before(r.Until) {
			until = r.Until
		}
	}
	if !from.IsZero() {
		query.Add("from", strconv.FormatInt(from.Unix(), 10))
	}
	if !until.IsZero() {
		query.Add("until", strconv.FormatInt(until.Unix(), 10))
	}
	return query
}
开发者ID:datacratic,项目名称:gotsvis,代码行数:25,代码来源:graphite_http.go

示例14: posts

func posts(url string, lastModified time.Time) []Post {
	doc, err := goquery.NewDocument(url)
	errNotNilToPanic(err)
	lastPage := 0
	doc.Find("ul").EachWithBreak(func(_ int, s *goquery.Selection) bool {
		if class, exist := s.Attr("class"); exist && class == "pagination" {
			if href, exist := s.Find("li").Find("a").Last().Attr("href"); exist {
				reg := regexp.MustCompile(".*page_num=([0-9]+)$")
				if m := reg.FindStringSubmatch(href); len(m) > 1 {
					lastPage, _ = strconv.Atoi(m[1])
				}
			}
			return false
		}
		return true
	})
	pList := []Post{}
	for page := 1; page <= lastPage; page++ {
		doc, err := goquery.NewDocument(url + "?comment_order=DESC&page_num=" + strconv.Itoa(page))
		errNotNilToPanic(err)
		doc.Find("div").EachWithBreak(func(_ int, s *goquery.Selection) bool {
			if class, exist := s.Attr("class"); exist && class == "post-sla" {
				p := post(s)
				if !lastModified.Before(p.postDate) {
					return false
				}
				pList = append(pList, p)
			}
			return true
		})
	}
	return pList
}
开发者ID:rajninorp,项目名称:pbget,代码行数:33,代码来源:petaboard.go

示例15: Chtimes

// Chtimes changes the access time and modified time of a file at the given path
func Chtimes(name string, atime time.Time, mtime time.Time) error {
	unixMinTime := time.Unix(0, 0)
	unixMaxTime := maxTime

	// If the modified time is prior to the Unix Epoch, or after the
	// end of Unix Time, os.Chtimes has undefined behavior
	// default to Unix Epoch in this case, just in case

	if atime.Before(unixMinTime) || atime.After(unixMaxTime) {
		atime = unixMinTime
	}

	if mtime.Before(unixMinTime) || mtime.After(unixMaxTime) {
		mtime = unixMinTime
	}

	if err := os.Chtimes(name, atime, mtime); err != nil {
		return err
	}

	// Take platform specific action for setting create time.
	if err := setCTime(name, mtime); err != nil {
		return err
	}

	return nil
}
开发者ID:CNDonny,项目名称:scope,代码行数:28,代码来源:chtimes.go


注:本文中的Time.Time.Before方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。