当前位置: 首页>>代码示例>>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;未经允许,请勿转载。