當前位置: 首頁>>代碼示例>>Golang>>正文


Golang Duration.Minutes方法代碼示例

本文整理匯總了Golang中Time.Duration.Minutes方法的典型用法代碼示例。如果您正苦於以下問題:Golang Duration.Minutes方法的具體用法?Golang Duration.Minutes怎麽用?Golang Duration.Minutes使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Time.Duration的用法示例。


在下文中一共展示了Duration.Minutes方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: fmtDuration

func fmtDuration(duration time.Duration) string {
	result := []string{}
	started := false
	if duration > 7*24*time.Hour || started {
		started = true
		weeks := int(duration.Hours() / 24 / 7)
		duration %= 7 * 24 * time.Hour
		result = append(result, fmt.Sprintf("%2dw", weeks))
	}
	if duration > 24*time.Hour || started {
		started = true
		days := int(duration.Hours() / 24)
		duration %= 24 * time.Hour
		result = append(result, fmt.Sprintf("%2dd", days))
	}
	if duration > time.Hour || started {
		started = true
		hours := int(duration.Hours())
		duration %= time.Hour
		result = append(result, fmt.Sprintf("%2dh", hours))
	}
	if duration > time.Minute || started {
		started = true
		minutes := int(duration.Minutes())
		duration %= time.Minute
		result = append(result, fmt.Sprintf("%2dm", minutes))
	}
	seconds := int(duration.Seconds())
	result = append(result, fmt.Sprintf("%2ds", seconds))
	return strings.TrimSpace(strings.Join(result, ""))
}
開發者ID:drj11,項目名稱:jump,代碼行數:31,代碼來源:duration.go

示例2: roundDuration

func roundDuration(d time.Duration) time.Duration {
	rd := time.Duration(d.Minutes()) * time.Minute
	if rd < d {
		rd += time.Minute
	}
	return rd
}
開發者ID:aliafshar,項目名稱:tools,代碼行數:7,代碼來源:parse.go

示例3: 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

示例4: 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

示例5: 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

示例6: SetDuration

// SetDuration sets the duration of an Usage
func (u *Usage) SetDuration(duration time.Duration) error {
	minutes := new(big.Rat).SetFloat64(duration.Minutes())
	factor := new(big.Rat).SetInt64((u.Object.UsageGranularity / time.Minute).Nanoseconds())
	quantity := new(big.Rat).Quo(minutes, factor)
	ceil := new(big.Rat).SetInt(ratCeil(quantity))
	return u.SetQuantity(ceil)
}
開發者ID:awesome-docker,項目名稱:scaleway-cli,代碼行數:8,代碼來源:usage.go

示例7: PrettyTime

func PrettyTime(d time.Duration) string {
	if d.Minutes() > 1 {
		return "" + strconv.Itoa(int(d.Minutes()))
	} else {
		return "Less than 1 min"
	}
}
開發者ID:siyegen,項目名稱:oswald,代碼行數:7,代碼來源:pom.go

示例8: 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

示例9: 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

示例10: 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

示例11: 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

示例12: 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

示例13: 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

示例14: FormatDuration

func FormatDuration(duration time.Duration) string {
	if duration.Minutes() >= 1 {
		sec := int(duration.Seconds()) % 60
		return fmt.Sprintf("%vm %vs", int(duration.Minutes()), sec)
	} else {
		return fmt.Sprintf("%0.1fs", duration.Seconds())
	}
}
開發者ID:joeferner,項目名稱:gorun,代碼行數:8,代碼來源:graph.go

示例15: durationToISO8601

func durationToISO8601(d time.Duration) (string, error) {
	if d > time.Hour {
		return "", fmt.Errorf("Duration is too long: %v", d)
	}
	minutes := int(math.Floor(d.Minutes()))
	seconds := int(math.Floor(d.Minutes()-float64(minutes)) * 60.0)
	return fmt.Sprintf("PT%dM%dS", minutes, seconds), nil
}
開發者ID:appittome,項目名稱:twiliogo,代碼行數:8,代碼來源:ip_service.go


注:本文中的Time.Duration.Minutes方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。