本文整理汇总了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, ""))
}
示例2: roundDuration
func roundDuration(d time.Duration) time.Duration {
rd := time.Duration(d.Minutes()) * time.Minute
if rd < d {
rd += time.Minute
}
return rd
}
示例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)
}
示例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)
}
示例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
}
示例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)
}
示例7: PrettyTime
func PrettyTime(d time.Duration) string {
if d.Minutes() > 1 {
return "" + strconv.Itoa(int(d.Minutes()))
} else {
return "Less than 1 min"
}
}
示例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))
}
}
示例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))
}
}
示例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)
}
示例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
}
示例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,
)
}
示例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)
}
示例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())
}
}
示例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
}