包装类型支持转为时间类型
This commit is contained in:
parent
2886126ae7
commit
faafa8ee2a
12
define.go
12
define.go
@ -7,6 +7,8 @@
|
||||
// Date : 2023-05-05 14:44
|
||||
package wrapper
|
||||
|
||||
import "time"
|
||||
|
||||
const (
|
||||
DataTypeUnknown = "unknown"
|
||||
DataTypeNil = "nil"
|
||||
@ -477,6 +479,16 @@ type Float64SliceResult struct {
|
||||
Err error
|
||||
}
|
||||
|
||||
// DurationResult 时间转换结果
|
||||
//
|
||||
// Author : zhangdeman001@ke.com<张德满>
|
||||
//
|
||||
// Date : 20:32 2023/9/4
|
||||
type DurationResult struct {
|
||||
Value time.Duration
|
||||
Err error
|
||||
}
|
||||
|
||||
// StringSliceResult ...
|
||||
//
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
|
13
int.go
13
int.go
@ -10,6 +10,7 @@ package wrapper
|
||||
import (
|
||||
"fmt"
|
||||
"math"
|
||||
"time"
|
||||
)
|
||||
|
||||
// Int int类型
|
||||
@ -19,6 +20,18 @@ import (
|
||||
// Date : 13:57 2023/5/5
|
||||
type Int int64
|
||||
|
||||
// ToDuration ...
|
||||
//
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 20:33 2023/9/4
|
||||
func (i Int) ToDuration(timeUnit time.Duration) DurationResult {
|
||||
return DurationResult{
|
||||
Value: time.Duration(i.ToInt64().Value) * timeUnit,
|
||||
Err: nil,
|
||||
}
|
||||
}
|
||||
|
||||
// ToInt8 ...
|
||||
//
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
|
16
string.go
16
string.go
@ -950,6 +950,22 @@ func (str String) ToNumberSlice(splitChar ...string) Float64SliceResult {
|
||||
return str.ToFloat64Slice(splitChar...)
|
||||
}
|
||||
|
||||
// ToDuration 转换为时间格式
|
||||
//
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 20:31 2023/9/4
|
||||
func (str String) ToDuration(timeUnit time.Duration) DurationResult {
|
||||
int64Val := str.ToInt64()
|
||||
if nil != int64Val.Err {
|
||||
return DurationResult{
|
||||
Value: 0,
|
||||
Err: int64Val.Err,
|
||||
}
|
||||
}
|
||||
return Int(int64Val.Value).ToDuration(timeUnit)
|
||||
}
|
||||
|
||||
// ToStringSlice ...
|
||||
//
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
|
Loading…
Reference in New Issue
Block a user