MM-25943: Upgrade dependencies for server (#14932)
* MM-25943: Upgrade dependencies for server * tmp
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
eff2209a7e
Коммит
d3156395a1
88
vendor/github.com/hako/durafmt/durafmt.go
сгенерированный
поставляемый
88
vendor/github.com/hako/durafmt/durafmt.go
сгенерированный
поставляемый
@@ -20,6 +20,13 @@ type Durafmt struct {
|
||||
duration time.Duration
|
||||
input string // Used as reference.
|
||||
limitN int // Non-zero to limit only first N elements to output.
|
||||
limitUnit string // Non-empty to limit max unit
|
||||
}
|
||||
|
||||
// LimitToUnit sets the output format, you will not have unit bigger than the UNIT specified. UNIT = "" means no restriction.
|
||||
func (d *Durafmt) LimitToUnit(unit string) *Durafmt {
|
||||
d.limitUnit = unit
|
||||
return d
|
||||
}
|
||||
|
||||
// LimitFirstN sets the output format, outputing only first N elements. n == 0 means no limit.
|
||||
@@ -31,14 +38,14 @@ func (d *Durafmt) LimitFirstN(n int) *Durafmt {
|
||||
// Parse creates a new *Durafmt struct, returns error if input is invalid.
|
||||
func Parse(dinput time.Duration) *Durafmt {
|
||||
input := dinput.String()
|
||||
return &Durafmt{dinput, input, 0}
|
||||
return &Durafmt{dinput, input, 0, ""}
|
||||
}
|
||||
|
||||
// ParseShort creates a new *Durafmt struct, short form, returns error if input is invalid.
|
||||
// It's shortcut for `Parse(dur).LimitFirstN(1)`
|
||||
func ParseShort(dinput time.Duration) *Durafmt {
|
||||
input := dinput.String()
|
||||
return &Durafmt{dinput, input, 1}
|
||||
return &Durafmt{dinput, input, 1, ""}
|
||||
}
|
||||
|
||||
// ParseString creates a new *Durafmt struct from a string.
|
||||
@@ -51,7 +58,7 @@ func ParseString(input string) (*Durafmt, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &Durafmt{duration, input, 0}, nil
|
||||
return &Durafmt{duration, input, 0, ""}, nil
|
||||
}
|
||||
|
||||
// ParseStringShort creates a new *Durafmt struct from a string, short form
|
||||
@@ -65,7 +72,7 @@ func ParseStringShort(input string) (*Durafmt, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &Durafmt{duration, input, 1}, nil
|
||||
return &Durafmt{duration, input, 1, ""}, nil
|
||||
}
|
||||
|
||||
// String parses d *Durafmt into a human readable duration.
|
||||
@@ -78,28 +85,65 @@ func (d *Durafmt) String() string {
|
||||
d.duration = -d.duration
|
||||
}
|
||||
|
||||
// Convert duration.
|
||||
seconds := int64(d.duration.Seconds()) % 60
|
||||
minutes := int64(d.duration.Minutes()) % 60
|
||||
hours := int64(d.duration.Hours()) % 24
|
||||
days := int64(d.duration/(24*time.Hour)) % 365 % 7
|
||||
var microseconds int64
|
||||
var milliseconds int64
|
||||
var seconds int64
|
||||
var minutes int64
|
||||
var hours int64
|
||||
var days int64
|
||||
var weeks int64
|
||||
var years int64
|
||||
var shouldConvert = false
|
||||
|
||||
// Edge case between 364 and 365 days.
|
||||
// We need to calculate weeks from what is left from years
|
||||
leftYearDays := int64(d.duration/(24*time.Hour)) % 365
|
||||
weeks := leftYearDays / 7
|
||||
if leftYearDays >= 364 && leftYearDays < 365 {
|
||||
weeks = 52
|
||||
remainingSecondsToConvert := int64(d.duration/time.Microsecond)
|
||||
|
||||
// Convert duration.
|
||||
if d.limitUnit == "" {
|
||||
shouldConvert = true
|
||||
}
|
||||
|
||||
years := int64(d.duration/(24*time.Hour)) / 365
|
||||
milliseconds := int64(d.duration/time.Millisecond) -
|
||||
(seconds * 1000) - (minutes * 60000) - (hours * 3600000) -
|
||||
(days * 86400000) - (weeks * 604800000) - (years * 31536000000)
|
||||
if d.limitUnit == "years" || shouldConvert {
|
||||
years = remainingSecondsToConvert / (365 * 24 * 3600 * 1000000)
|
||||
remainingSecondsToConvert -= years * 365 * 24 * 3600 * 1000000
|
||||
shouldConvert = true
|
||||
}
|
||||
|
||||
microseconds := int64(d.duration/time.Microsecond) -
|
||||
(milliseconds * 1000) - (seconds * 1000000) - (minutes * 60000000) - (hours * 3600000000) -
|
||||
(days * 86400000000) - (weeks * 604800000000) - (years * 31536000000000)
|
||||
if d.limitUnit == "weeks" || shouldConvert {
|
||||
weeks = remainingSecondsToConvert / (7 * 24 * 3600 * 1000000)
|
||||
remainingSecondsToConvert -= weeks * 7 * 24 * 3600 * 1000000
|
||||
shouldConvert = true
|
||||
}
|
||||
|
||||
if d.limitUnit == "days" || shouldConvert {
|
||||
days = remainingSecondsToConvert / (24 * 3600 * 1000000)
|
||||
remainingSecondsToConvert -= days * 24 * 3600 * 1000000
|
||||
shouldConvert = true
|
||||
}
|
||||
|
||||
if d.limitUnit == "hours" || shouldConvert {
|
||||
hours = remainingSecondsToConvert / (3600 * 1000000)
|
||||
remainingSecondsToConvert -= hours * 3600 * 1000000
|
||||
shouldConvert = true
|
||||
}
|
||||
|
||||
if d.limitUnit == "minutes" || shouldConvert {
|
||||
minutes = remainingSecondsToConvert / (60 * 1000000)
|
||||
remainingSecondsToConvert -= minutes * 60 * 1000000
|
||||
shouldConvert = true
|
||||
}
|
||||
|
||||
if d.limitUnit == "seconds" || shouldConvert {
|
||||
seconds = remainingSecondsToConvert / 1000000
|
||||
remainingSecondsToConvert -= seconds * 1000000
|
||||
shouldConvert = true
|
||||
}
|
||||
|
||||
if d.limitUnit == "milliseconds" || shouldConvert {
|
||||
milliseconds = remainingSecondsToConvert / 1000
|
||||
remainingSecondsToConvert -= milliseconds * 1000
|
||||
}
|
||||
|
||||
microseconds = remainingSecondsToConvert
|
||||
|
||||
// Create a map of the converted duration time.
|
||||
durationMap := map[string]int64{
|
||||
|
||||
Ссылка в новой задаче
Block a user