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


Golang Duration.Hours方法代码示例

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


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

示例1: FormattedSecondsToMax8Chars

// FormattedSecondsToMax8Chars ...
func FormattedSecondsToMax8Chars(t time.Duration) (string, error) {
	sec := t.Seconds()
	min := t.Minutes()
	hour := t.Hours()

	if sec < 1.0 {
		// 0.999999 sec -> 0.99 sec
		return fmt.Sprintf("%.2f sec", sec), nil // 8
	} else if sec < 10.0 {
		// 9.99999 sec -> 9.99 sec
		return fmt.Sprintf("%.2f sec", sec), nil // 8
	} else if sec < 600 {
		// 599,999 sec -> 599 sec
		return fmt.Sprintf("%.f sec", sec), nil // 7
	} else if min < 60 {
		// 59,999 min -> 59.9 min
		return fmt.Sprintf("%.1f min", min), nil // 8
	} else if hour < 10 {
		// 9.999 hour -> 9.9 hour
		return fmt.Sprintf("%.1f hour", hour), nil // 8
	} else if hour < 1000 {
		// 999,999 hour -> 999 hour
		return fmt.Sprintf("%.f hour", hour), nil // 8
	}

	return "", fmt.Errorf("time (%f hour) greater then max allowed (999 hour)", hour)
}
开发者ID:bitrise-io,项目名称:bitrise,代码行数:28,代码来源:util.go

示例2: LogFetches

// LogFetches processes all the Fetch items are writes the log to S3 for the parsers to start working.
func LogFetches(logChan <-chan *Fetch, errChan <-chan *FetchError, duration *time.Duration) {
	report := &Report{Novel: 0, Errors: 0, Total: 0}
	fetchDuration := &FetchDuration{Hours: duration.Hours(), Minutes: duration.Minutes(), Seconds: duration.Seconds()}
	fetches := &Fetches{}
	for fetch := range logChan {
		fetches.Fetch = append(fetches.Fetch, fetch)
		if fetch.Novel {
			report.Novel++
		}
		report.Total++
	}

	for err := range errChan {
		fetches.FetchError = append(fetches.FetchError, err)
		report.Errors++
		report.Total++
	}

	fetches.Meta = &Meta{FetchDuration: fetchDuration, Report: report}

	content, _ := xml.MarshalIndent(fetches, "", "\t")

	// Write to S3.
	logPath := logFilePath()
	s3content := []byte(xml.Header + string(content))
	S3BucketFromOS().Put(logPath, s3content, "application/xml", s3.Private)
}
开发者ID:ChristopherRabotin,项目名称:gofetch,代码行数:28,代码来源:s3mgr.go

示例3: renderFixedSizeDuration

func (this *ProgressBarSimple) renderFixedSizeDuration(dur time.Duration) string {
	h := dur.Hours()
	m := dur.Minutes()
	if h > pbYear*10 {
		y := int(h / pbYear)
		h -= float64(y) * pbYear
		w := h / pbWeek
		return fmt.Sprintf("%02dy%02dw", y, int(w))
	} else if h > pbWeek*10 {
		return fmt.Sprintf("%05dw", int(h/pbWeek))
	} else if h > pbDay*2 {
		d := int(h / pbDay)
		h -= pbDay * float64(d)
		return fmt.Sprintf("%02dd%02dh", d, int(h))
	} else if h > 1 {
		o := int(h)
		i := m - float64(o)*60
		return fmt.Sprintf("%02dh%02dm", o, int(i))
	} else if dur.Seconds() < 0 {
		return "00m00s"
	} else {
		i := int(m)
		s := dur.Seconds() - float64(i)*60
		return fmt.Sprintf("%02dm%02ds", i, int(s))
	}
}
开发者ID:escribano,项目名称:clif,代码行数:26,代码来源:progress_bar.go

示例4: relativeTime

func relativeTime(duration time.Duration) string {
	hours := int64(math.Abs(duration.Hours()))
	minutes := int64(math.Abs(duration.Minutes()))
	when := ""
	switch {
	case hours >= (365 * 24):
		when = "Over an year ago"
	case hours > (30 * 24):
		when = fmt.Sprintf("%d months ago", int64(hours/(30*24)))
	case hours == (30 * 24):
		when = "a month ago"
	case hours > 24:
		when = fmt.Sprintf("%d days ago", int64(hours/24))
	case hours == 24:
		when = "yesterday"
	case hours >= 2:
		when = fmt.Sprintf("%d hours ago", hours)
	case hours > 1:
		when = "over an hour ago"
	case hours == 1:
		when = "an hour ago"
	case minutes >= 2:
		when = fmt.Sprintf("%d minutes ago", minutes)
	case minutes > 1:
		when = "a minute ago"
	default:
		when = "just now"
	}
	return when
}
开发者ID:kristofer,项目名称:goshorty,代码行数:30,代码来源:app.go

示例5: FriendlyDuration

func FriendlyDuration(d time.Duration) string {
	switch {
	case d.Hours() >= 24:
		days := int(d.Hours() / 24)
		hours := int(d.Hours()) - days*24
		return joinpair(plural(days, "day"), plural(hours, "hour"))
	case d.Hours() >= 1:
		hours := int(d.Hours())
		mins := int(int(d.Minutes()) - 60*hours)
		return joinpair(plural(hours, "hour"), plural(mins, "minute"))
	case d.Minutes() >= 1:
		mins := int(d.Minutes())
		secs := int(int(d.Seconds()) - 60*mins)
		return joinpair(plural(mins, "minute"), plural(secs, "second"))
	case d.Seconds() >= 1:
		secs := int(d.Seconds())
		return plural(secs, "second")
	case d.Nanoseconds() >= 1000:
		ms := int(d.Seconds() * 1000)
		return plural(ms, "millisecond")
	case d.Nanoseconds() > 0:
		ns := d.Nanoseconds()
		return plural(int(ns), "nanosecond")
	}
	return "0 seconds"
}
开发者ID:kienhung,项目名称:gohome,代码行数:26,代码来源:time.go

示例6: RenderFixedSizeDuration

func RenderFixedSizeDuration(dur time.Duration) string {
	h := dur.Hours()
	m := dur.Minutes()
	s := dur.Seconds()
	if h > pbYear*10 {
		y := int(h / pbYear)
		h -= float64(y) * pbYear
		w := h / pbWeek
		return fmt.Sprintf("%02dy%02dw", y, int(w))
	} else if h > pbWeek*10 {
		return fmt.Sprintf("%05dw", int(h/pbWeek))
	} else if h > pbDay*2 {
		d := int(h / pbDay)
		h -= pbDay * float64(d)
		return fmt.Sprintf("%02dd%02dh", d, int(h))
	} else if h > 1 {
		o := int(h)
		i := m - float64(o)*60
		return fmt.Sprintf("%02dh%02dm", o, int(i))
	} else if s > 99 {
		i := int(m)
		o := s - float64(i)*60
		return fmt.Sprintf("%02dm%02ds", i, int(o))
	} else if s < 1 {
		return "00m00s"
	} else {
		ms := (s - float64(int(s))) * 1000
		return fmt.Sprintf("%02ds%03d", int(s), int(ms))
	}
}
开发者ID:escribano,项目名称:clif,代码行数:30,代码来源:progress_bar.go

示例7: list

//	list request all entries from the database, and the displays them.
func list() {
	// get all the entries
	var entries []entry.Entry
	jsonRequest("GET", "/entries", &entries)

	fmt.Println("\nAll Entries")
	fmt.Println("-------------------------------------")

	var total time.Duration

	for _, e := range entries {
		if e.Ended() {
			fmt.Printf("-- %d\t%s\t%s\n", e.Id, e.TimeString(), e.Msg)
		} else {
			fmt.Printf("-- \033[033m%d\t%s\t%s%s\n",
				e.Id,
				e.TimeString(),
				e.Msg,
				" <= active \033[0m")
		}

		total = total + e.Duration()
	}

	fmt.Println("-------------------------------------")
	fmt.Printf("Total - %dh %dm %ds\n\n",
		int(total.Hours()),
		int(total.Minutes())%60,
		int(total.Seconds())%60)
}
开发者ID:rharriso,项目名称:waid,代码行数:31,代码来源:waid.go

示例8: dur2secs

func dur2secs(dur time.Duration) (secs float32) {
	secs = float32(dur.Hours() * 3600)
	secs += float32(dur.Minutes() * 60)
	secs += float32(dur.Seconds())
	secs += float32(dur.Nanoseconds()) * float32(0.000000001)
	return secs
}
开发者ID:tartaruszen,项目名称:dbstream,代码行数:7,代码来源:stats.go

示例9: FormatDuration

// Formats the given duration as more readable string.
func FormatDuration(dur *time.Duration) string {
	var days int = int(dur.Hours() / 24)
	var hrs int = int(dur.Hours()) % 24
	var mins int = int(dur.Minutes()) % 60
	var secs int = int(dur.Seconds()) % 60

	return fmt.Sprintf("%d days, %d hours, %d minutes and %d seconds", days, hrs, mins, secs)
}
开发者ID:krpors,项目名称:stats,代码行数:9,代码来源:main.go

示例10: getDurationString

func getDurationString(duration time.Duration) string {
	return fmt.Sprintf(
		"%0.2d:%02d:%02d",
		int(duration.Hours()),
		int(duration.Minutes())%60,
		int(duration.Seconds())%60,
	)
}
开发者ID:iopred,项目名称:bruxism,代码行数:8,代码来源:statsplugin.go

示例11: fmtDuration

func fmtDuration(d time.Duration) string {
	if d.Hours() >= 1 {
		return fmt.Sprintf("%vh%vm", int(d.Hours()), int(d.Minutes())%60)
	} else if d.Minutes() >= 1 {
		return fmt.Sprintf("%vm%vs", int(d.Minutes()), int(d.Seconds())%60)
	} else {
		return fmt.Sprintf("%vs", int(d.Seconds()))
	}
}
开发者ID:stephens2424,项目名称:go-fuzz,代码行数:9,代码来源:master.go

示例12: deltaNow

func deltaNow(t time.Time) (time.Duration, string) {
	var suff string
	var d time.Duration

	now := time.Now()
	if now.Before(t) {
		suff = "ahead"
		d = t.Sub(now)
	} else {
		suff = "ago"
		d = now.Sub(t)
	}
	if d < 1*time.Second {
		return time.Duration(0), "right now"
	}

	interv := []struct {
		d    time.Duration
		desc string
	}{
		{time.Minute, "minute"},
		{time.Hour, "hour"},
		{24 * time.Hour, "day"},
		{7 * 24 * time.Hour, "week"},
	}

	var roughly string
	for _, i := range interv {
		if d < i.d {
			roughly = "within the " + i.desc + ", "
			break
		}
	}

	days, hours, minutes, seconds := 0, int(d.Hours()), int(d.Minutes()), int(d.Seconds())
	minutes -= 60 * hours
	seconds -= 3600*hours + 60*minutes
	for hours >= 24 {
		days += 1
		hours -= 24
	}
	exact := suff
	plural := map[bool]string{true: "s", false: ""}
	if seconds != 0 {
		exact = fmt.Sprintf("%d second%s %s", seconds, plural[seconds > 1], exact)
	}
	if minutes != 0 {
		exact = fmt.Sprintf("%d minute%s %s", minutes, plural[minutes > 1], exact)
	}
	if hours != 0 {
		exact = fmt.Sprintf("%d hour%s %s", hours, plural[hours > 1], exact)
	}
	if days != 0 {
		exact = fmt.Sprintf("%d day%s %s", days, plural[days > 1], exact)
	}
	return d, roughly + exact
}
开发者ID:Feh,项目名称:guess,代码行数:57,代码来源:guess.go

示例13: writeTime

// Writes a duration formatted as hours:minues:seconds,milliseconds
func writeTime(w io.Writer, dur time.Duration) (nbytes int, err error) {
	hoursToPrint := int(math.Floor(dur.Hours()))
	minutesToPrint := int(math.Floor(dur.Minutes() - (time.Duration(hoursToPrint) * time.Hour).Minutes()))
	secondsToPrint := int(math.Floor(dur.Seconds() - (time.Duration(hoursToPrint)*time.Hour + time.Duration(minutesToPrint)*time.Minute).Seconds()))
	millisecondsToPrint := int(math.Floor(float64(dur/time.Millisecond - (time.Duration(hoursToPrint)*time.Hour+time.Duration(minutesToPrint)*time.Minute+time.Duration(secondsToPrint)*time.Second)/time.Millisecond)))

	nbytes, err = fmt.Fprintf(w, "%02d:%02d:%02d,%03d", hoursToPrint, minutesToPrint, secondsToPrint, millisecondsToPrint)
	return
}
开发者ID:n00bDooD,项目名称:gosrt,代码行数:10,代码来源:subtitleWriter.go

示例14: durationStr

// durationStr returns duration d in a human readable simple format:
// "2.5 hours", "1 hour", "30 minutes", etc.
func durationStr(d time.Duration) string {
	if d < time.Hour {
		return fmt.Sprintf("%d minutes", int(d.Minutes()))
	}
	v, u := d.Hours(), "hour"
	if v > 1.5 {
		u += "s"
	}
	return fmt.Sprintf("%g %s", d.Hours(), u)
}
开发者ID:CadeLaRen,项目名称:ioweb2016,代码行数:12,代码来源:schedule.go

示例15: durationToString

func durationToString(d time.Duration) string {
	hours := int(math.Trunc(d.Hours()))
	minutes := int(math.Trunc(d.Minutes())) - 60*hours
	seconds := int(d.Seconds()) % 60

	if hours > 0 {
		return fmt.Sprintf("%d:%d:%02d", hours, minutes, seconds)
	}

	return fmt.Sprintf("%d:%02d", minutes, seconds)
}
开发者ID:kalafut,项目名称:gmw,代码行数:11,代码来源:web.go


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