MM-33945: Update dependencies (#17201)
* MM-33945: Update dependencies Ran `make update-dependencies` https://mattermost.atlassian.net/browse/MM-33945 ```release-notes NONE ``` * fix test
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
adcddf350e
Коммит
b950125d4e
38
vendor/github.com/hako/durafmt/README.md
сгенерированный
поставляемый
38
vendor/github.com/hako/durafmt/README.md
сгенерированный
поставляемый
@@ -34,7 +34,6 @@ package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/hako/durafmt"
|
||||
)
|
||||
|
||||
@@ -57,7 +56,6 @@ package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/hako/durafmt"
|
||||
)
|
||||
|
||||
@@ -79,7 +77,6 @@ package main
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/hako/durafmt"
|
||||
)
|
||||
|
||||
@@ -100,7 +97,6 @@ package main
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/hako/durafmt"
|
||||
)
|
||||
|
||||
@@ -111,6 +107,38 @@ func main() {
|
||||
}
|
||||
```
|
||||
|
||||
#### Custom Units
|
||||
|
||||
Like `durafmt.Units{}` and `durafmt.Durafmt.Format(units)` to stringify duration with custom units.
|
||||
|
||||
```go
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
"github.com/hako/durafmt"
|
||||
)
|
||||
|
||||
func main() {
|
||||
timeduration := (354 * time.Hour) + (22 * time.Minute) + (1 * time.Second) + (100*time.Microsecond)
|
||||
duration := durafmt.Parse(timeduration)
|
||||
// units in portuguese
|
||||
units, err := durafmt.DefaultUnitsCoder.Decode("ano,semana,dia,hora,minuto,segundo,milissegundo,microssegundo")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
fmt.Println(duration.Format(units)) // 2 semanas 18 horas 22 minutos 1 segundo 100 microssegundos
|
||||
|
||||
// custom plural (singular:plural)
|
||||
units, err = durafmt.DefaultUnitsCoder.Decode("ano,semana:SEMANAS,dia,hora,minuto,segundo,milissegundo,microssegundo")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
fmt.Println(duration.Format(units)) // 2 SEMANAS 18 horas 22 minutos 1 segundo 100 microssegundos
|
||||
}
|
||||
```
|
||||
|
||||
# Contributing
|
||||
|
||||
Contributions are welcome! Fork this repo, add your changes and submit a PR.
|
||||
@@ -123,4 +151,4 @@ When contributing, running `go test; go vet; golint` or `golangci-lint` is recom
|
||||
|
||||
# License
|
||||
|
||||
MIT
|
||||
MIT
|
||||
|
||||
152
vendor/github.com/hako/durafmt/durafmt.go
сгенерированный
поставляемый
152
vendor/github.com/hako/durafmt/durafmt.go
сгенерированный
поставляемый
@@ -11,7 +11,7 @@ import (
|
||||
)
|
||||
|
||||
var (
|
||||
units = []string{"years", "weeks", "days", "hours", "minutes", "seconds", "milliseconds", "microseconds"}
|
||||
units, _ = DefaultUnitsCoder.Decode("year,week,day,hour,minute,second,millisecond,microsecond")
|
||||
unitsShort = []string{"y", "w", "d", "h", "m", "s", "ms", "µs"}
|
||||
)
|
||||
|
||||
@@ -79,8 +79,136 @@ func ParseStringShort(input string) (*Durafmt, error) {
|
||||
return &Durafmt{duration, input, 1, ""}, nil
|
||||
}
|
||||
|
||||
// String parses d *Durafmt into a human readable duration.
|
||||
// String parses d *Durafmt into a human readable duration with default units.
|
||||
func (d *Durafmt) String() string {
|
||||
return d.Format(units)
|
||||
}
|
||||
|
||||
// Format parses d *Durafmt into a human readable duration with units.
|
||||
func (d *Durafmt) Format(units Units) string {
|
||||
var duration string
|
||||
|
||||
// Check for minus durations.
|
||||
if string(d.input[0]) == "-" {
|
||||
duration += "-"
|
||||
d.duration = -d.duration
|
||||
}
|
||||
|
||||
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
|
||||
|
||||
remainingSecondsToConvert := int64(d.duration / time.Microsecond)
|
||||
|
||||
// Convert duration.
|
||||
if d.limitUnit == "" {
|
||||
shouldConvert = true
|
||||
}
|
||||
|
||||
if d.limitUnit == "years" || shouldConvert {
|
||||
years = remainingSecondsToConvert / (365 * 24 * 3600 * 1000000)
|
||||
remainingSecondsToConvert -= years * 365 * 24 * 3600 * 1000000
|
||||
shouldConvert = true
|
||||
}
|
||||
|
||||
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 := []int64{
|
||||
microseconds,
|
||||
milliseconds,
|
||||
seconds,
|
||||
minutes,
|
||||
hours,
|
||||
days,
|
||||
weeks,
|
||||
years,
|
||||
}
|
||||
|
||||
// Construct duration string.
|
||||
for i, u := range units.Units() {
|
||||
v := durationMap[7-i]
|
||||
strval := strconv.FormatInt(v, 10)
|
||||
switch {
|
||||
// add to the duration string if v > 1.
|
||||
case v > 1:
|
||||
duration += strval + " " + u.Plural + " "
|
||||
// remove the plural 's', if v is 1.
|
||||
case v == 1:
|
||||
duration += strval + " " + u.Singular + " "
|
||||
// omit any value with 0s or 0.
|
||||
case d.duration.String() == "0" || d.duration.String() == "0s":
|
||||
pattern := fmt.Sprintf("^-?0%s$", unitsShort[i])
|
||||
isMatch, err := regexp.MatchString(pattern, d.input)
|
||||
if err != nil {
|
||||
return ""
|
||||
}
|
||||
if isMatch {
|
||||
duration += strval + " " + u.Plural
|
||||
}
|
||||
|
||||
// omit any value with 0.
|
||||
case v == 0:
|
||||
continue
|
||||
}
|
||||
}
|
||||
// trim any remaining spaces.
|
||||
duration = strings.TrimSpace(duration)
|
||||
|
||||
// if more than 2 spaces present return the first 2 strings
|
||||
// if short version is requested
|
||||
if d.limitN > 0 {
|
||||
parts := strings.Split(duration, " ")
|
||||
if len(parts) > d.limitN*2 {
|
||||
duration = strings.Join(parts[:d.limitN*2], " ")
|
||||
}
|
||||
}
|
||||
|
||||
return duration
|
||||
}
|
||||
|
||||
func (d *Durafmt) InternationalString() string {
|
||||
var duration string
|
||||
|
||||
// Check for minus durations.
|
||||
@@ -151,19 +279,19 @@ func (d *Durafmt) String() string {
|
||||
|
||||
// Create a map of the converted duration time.
|
||||
durationMap := map[string]int64{
|
||||
"microseconds": microseconds,
|
||||
"milliseconds": milliseconds,
|
||||
"seconds": seconds,
|
||||
"minutes": minutes,
|
||||
"hours": hours,
|
||||
"days": days,
|
||||
"weeks": weeks,
|
||||
"years": years,
|
||||
"µs": microseconds,
|
||||
"ms": milliseconds,
|
||||
"s": seconds,
|
||||
"m": minutes,
|
||||
"h": hours,
|
||||
"d": days,
|
||||
"w": weeks,
|
||||
"y": years,
|
||||
}
|
||||
|
||||
// Construct duration string.
|
||||
for i := range units {
|
||||
u := units[i]
|
||||
for i := range units.Units() {
|
||||
u := unitsShort[i]
|
||||
v := durationMap[u]
|
||||
strval := strconv.FormatInt(v, 10)
|
||||
switch {
|
||||
|
||||
3
vendor/github.com/hako/durafmt/go.mod
сгенерированный
поставляемый
Обычный файл
3
vendor/github.com/hako/durafmt/go.mod
сгенерированный
поставляемый
Обычный файл
@@ -0,0 +1,3 @@
|
||||
module github.com/hako/durafmt
|
||||
|
||||
go 1.11
|
||||
108
vendor/github.com/hako/durafmt/unit.go
сгенерированный
поставляемый
Обычный файл
108
vendor/github.com/hako/durafmt/unit.go
сгенерированный
поставляемый
Обычный файл
@@ -0,0 +1,108 @@
|
||||
package durafmt
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// DefaultUnitsCoder default units coder using `":"` as PluralSep and `","` as UnitsSep
|
||||
var DefaultUnitsCoder = UnitsCoder{":", ","}
|
||||
|
||||
// Unit the pair of singular and plural units
|
||||
type Unit struct {
|
||||
Singular, Plural string
|
||||
}
|
||||
|
||||
// Units duration units
|
||||
type Units struct {
|
||||
Year, Week, Day, Hour, Minute,
|
||||
Second, Millisecond, Microsecond Unit
|
||||
}
|
||||
|
||||
// Units return a slice of units
|
||||
func (u Units) Units() []Unit {
|
||||
return []Unit{u.Year, u.Week, u.Day, u.Hour, u.Minute,
|
||||
u.Second, u.Millisecond, u.Microsecond}
|
||||
}
|
||||
|
||||
// UnitsCoder the units encoder and decoder
|
||||
type UnitsCoder struct {
|
||||
// PluralSep char to sep singular and plural pair.
|
||||
// Example with char `":"`: `"year:year"` (english) or `"mês:meses"` (portuguese)
|
||||
PluralSep,
|
||||
// UnitsSep char to sep units (singular and plural pairs).
|
||||
// Example with char `","`: `"year:year,week:weeks"` (english) or `"mês:meses,semana:semanas"` (portuguese)
|
||||
UnitsSep string
|
||||
}
|
||||
|
||||
// Encode encodes input Units to string
|
||||
// Examples with `UnitsCoder{PluralSep: ":", UnitsSep = ","}`
|
||||
// - singular and plural pair units: `"year:wers,week:weeks,day:days,hour:hours,minute:minutes,second:seconds,millisecond:millliseconds,microsecond:microsseconds"`
|
||||
func (coder UnitsCoder) Encode(units Units) string {
|
||||
var pairs = make([]string, 8)
|
||||
for i, u := range units.Units() {
|
||||
pairs[i] = u.Singular + coder.PluralSep + u.Plural
|
||||
}
|
||||
return strings.Join(pairs, coder.UnitsSep)
|
||||
}
|
||||
|
||||
// Decode decodes input string to Units.
|
||||
// The input must follow the following formats:
|
||||
// - Unit format (singular and plural pair)
|
||||
// - must singular (the plural receives 's' character as suffix)
|
||||
// - singular and plural: separated by `PluralSep` char
|
||||
// Example with char `":"`: `"year:year"` (english) or `"mês:meses"` (portuguese)
|
||||
// - Units format (pairs of Year, Week, Day, Hour, Minute,
|
||||
// Second, Millisecond and Microsecond units) separated by `UnitsSep` char
|
||||
// - Examples with `UnitsCoder{PluralSep: ":", UnitsSep = ","}`
|
||||
// - must singular units: `"year,week,day,hour,minute,second,millisecond,microsecond"`
|
||||
// - mixed units: `"year,week:weeks,day,hour,minute:minutes,second,millisecond,microsecond"`
|
||||
// - singular and plural pair units: `"year:wers,week:weeks,day:days,hour:hours,minute:minutes,second:seconds,millisecond:millliseconds,microsecond:microsseconds"`
|
||||
func (coder UnitsCoder) Decode(s string) (units Units, err error) {
|
||||
parts := strings.Split(s, coder.UnitsSep)
|
||||
if len(parts) != 8 {
|
||||
err = fmt.Errorf("bad parts length")
|
||||
return units, err
|
||||
}
|
||||
|
||||
var parse = func(name, part string, u *Unit) bool {
|
||||
ps := strings.Split(part, coder.PluralSep)
|
||||
switch len(ps) {
|
||||
case 1:
|
||||
// create plural form with sigular + 's' suffix
|
||||
u.Singular, u.Plural = ps[0], ps[0]+"s"
|
||||
case 2:
|
||||
u.Singular, u.Plural = ps[0], ps[1]
|
||||
default:
|
||||
err = fmt.Errorf("bad unit %q pair length", name)
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
if !parse("Year", parts[0], &units.Year) {
|
||||
return units, err
|
||||
}
|
||||
if !parse("Week", parts[1], &units.Week) {
|
||||
return units, err
|
||||
}
|
||||
if !parse("Day", parts[2], &units.Day) {
|
||||
return units, err
|
||||
}
|
||||
if !parse("Hour", parts[3], &units.Hour) {
|
||||
return units, err
|
||||
}
|
||||
if !parse("Minute", parts[4], &units.Minute) {
|
||||
return units, err
|
||||
}
|
||||
if !parse("Second", parts[5], &units.Second) {
|
||||
return units, err
|
||||
}
|
||||
if !parse("Millisecond", parts[6], &units.Millisecond) {
|
||||
return units, err
|
||||
}
|
||||
if !parse("Microsecond", parts[7], &units.Microsecond) {
|
||||
return units, err
|
||||
}
|
||||
return units, err
|
||||
}
|
||||
Ссылка в новой задаче
Block a user