Upgrading server dependency. (#8807)
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
d3ead7dc85
Коммит
d5e1f7e298
44
vendor/github.com/hako/durafmt/README.md
сгенерированный
поставляемый
44
vendor/github.com/hako/durafmt/README.md
сгенерированный
поставляемый
@@ -33,7 +33,7 @@ The above seems very easy to read, unless your duration looks like this:
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"fmt"
|
||||
"github.com/hako/durafmt"
|
||||
)
|
||||
|
||||
@@ -47,6 +47,28 @@ func main() {
|
||||
}
|
||||
```
|
||||
|
||||
### durafmt.ParseStringShort()
|
||||
|
||||
Version of `durafmt.ParseString()` that only returns the first part of the duration string.
|
||||
|
||||
```go
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/hako/durafmt"
|
||||
)
|
||||
|
||||
func main() {
|
||||
duration, err := durafmt.ParseStringShort("354h22m3.24s")
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
fmt.Println(duration) // 2 weeks
|
||||
// duration.String() // String short representation. "2 weeks"
|
||||
}
|
||||
```
|
||||
|
||||
### durafmt.Parse()
|
||||
|
||||
```go
|
||||
@@ -65,6 +87,26 @@ func main() {
|
||||
}
|
||||
```
|
||||
|
||||
### durafmt.ParseShort()
|
||||
|
||||
Version of `durafmt.Parse()` that only returns the first part of the duration string.
|
||||
|
||||
```go
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
"github.com/hako/durafmt"
|
||||
)
|
||||
|
||||
func main() {
|
||||
timeduration := (354 * time.Hour) + (22 * time.Minute) + (3 * time.Second)
|
||||
duration := durafmt.ParseShort(timeduration).String()
|
||||
fmt.Println(duration) // 2 weeks
|
||||
}
|
||||
```
|
||||
|
||||
# Contributing
|
||||
|
||||
Contributions are welcome! Fork this repo and add your changes and submit a PR.
|
||||
|
||||
31
vendor/github.com/hako/durafmt/durafmt.go
сгенерированный
поставляемый
31
vendor/github.com/hako/durafmt/durafmt.go
сгенерированный
поставляемый
@@ -16,12 +16,19 @@ var (
|
||||
type Durafmt struct {
|
||||
duration time.Duration
|
||||
input string // Used as reference.
|
||||
short bool
|
||||
}
|
||||
|
||||
// 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}
|
||||
return &Durafmt{dinput, input, false}
|
||||
}
|
||||
|
||||
// ParseShort creates a new *Durafmt struct, short form, returns error if input is invalid.
|
||||
func ParseShort(dinput time.Duration) *Durafmt {
|
||||
input := dinput.String()
|
||||
return &Durafmt{dinput, input, true}
|
||||
}
|
||||
|
||||
// ParseString creates a new *Durafmt struct from a string.
|
||||
@@ -34,7 +41,20 @@ func ParseString(input string) (*Durafmt, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &Durafmt{duration, input}, nil
|
||||
return &Durafmt{duration, input, false}, nil
|
||||
}
|
||||
|
||||
// ParseStringShort creates a new *Durafmt struct from a string, short form
|
||||
// returns an error if input is invalid.
|
||||
func ParseStringShort(input string) (*Durafmt, error) {
|
||||
if input == "0" || input == "-0" {
|
||||
return nil, errors.New("durafmt: missing unit in duration " + input)
|
||||
}
|
||||
duration, err := time.ParseDuration(input)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &Durafmt{duration, input, true}, nil
|
||||
}
|
||||
|
||||
// String parses d *Durafmt into a human readable duration.
|
||||
@@ -116,5 +136,12 @@ func (d *Durafmt) String() string {
|
||||
}
|
||||
// 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.short {
|
||||
duration = strings.Join(strings.Split(duration, " ")[:2], " ")
|
||||
}
|
||||
|
||||
return duration
|
||||
}
|
||||
|
||||
Ссылка в новой задаче
Block a user