Compare commits

...

5 Commits

Author SHA1 Message Date
Bobo
3ec9bbbd27 feat: time util 2025-05-28 23:58:08 +08:00
Bobo
faa5817857 feat: time util 2025-05-28 23:55:43 +08:00
Bobo
89a69a9d4d feat: entgo 2025-05-28 23:29:21 +08:00
Bobo
63789d090d feat: entgo 2025-05-28 23:08:18 +08:00
Bobo
06c29c57d2 feat: copier util 2025-05-28 23:06:30 +08:00
7 changed files with 28 additions and 18 deletions

View File

@@ -6,7 +6,7 @@ toolchain go1.24.3
require ( require (
github.com/jinzhu/copier v0.4.0 github.com/jinzhu/copier v0.4.0
github.com/tx7do/go-utils v1.1.22 github.com/tx7do/go-utils v1.1.24
) )
require ( require (

View File

@@ -11,7 +11,7 @@ require (
github.com/go-kratos/kratos/v2 v2.8.4 github.com/go-kratos/kratos/v2 v2.8.4
github.com/google/uuid v1.6.0 github.com/google/uuid v1.6.0
github.com/stretchr/testify v1.10.0 github.com/stretchr/testify v1.10.0
github.com/tx7do/go-utils v1.1.22 github.com/tx7do/go-utils v1.1.24
go.opentelemetry.io/otel v1.36.0 go.opentelemetry.io/otel v1.36.0
google.golang.org/protobuf v1.36.6 google.golang.org/protobuf v1.36.6
) )
@@ -23,7 +23,7 @@ require (
github.com/bmatcuk/doublestar v1.3.4 // indirect github.com/bmatcuk/doublestar v1.3.4 // indirect
github.com/bufbuild/protocompile v0.14.1 // indirect github.com/bufbuild/protocompile v0.14.1 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect github.com/davecgh/go-spew v1.1.1 // indirect
github.com/go-logr/logr v1.4.2 // indirect github.com/go-logr/logr v1.4.3 // indirect
github.com/go-logr/stdr v1.2.2 // indirect github.com/go-logr/stdr v1.2.2 // indirect
github.com/go-openapi/inflect v0.21.2 // indirect github.com/go-openapi/inflect v0.21.2 // indirect
github.com/golang/protobuf v1.5.4 // indirect github.com/golang/protobuf v1.5.4 // indirect

View File

@@ -23,6 +23,8 @@ github.com/go-kratos/kratos/v2 v2.8.4/go.mod h1:mq62W2101a5uYyRxe+7IdWubu7gZCGYq
github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
github.com/go-logr/logr v1.4.2 h1:6pFjapn8bFcIbiKo3XT4j/BhANplGihG6tvd+8rYgrY= github.com/go-logr/logr v1.4.2 h1:6pFjapn8bFcIbiKo3XT4j/BhANplGihG6tvd+8rYgrY=
github.com/go-logr/logr v1.4.2/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY= github.com/go-logr/logr v1.4.2/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
github.com/go-logr/logr v1.4.3 h1:CjnDlHq8ikf6E492q6eKboGOC0T8CDaOvkHCIg8idEI=
github.com/go-logr/logr v1.4.3/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag= github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag=
github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE= github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE=
github.com/go-openapi/inflect v0.21.2 h1:0gClGlGcxifcJR56zwvhaOulnNgnhc4qTAkob5ObnSM= github.com/go-openapi/inflect v0.21.2 h1:0gClGlGcxifcJR56zwvhaOulnNgnhc4qTAkob5ObnSM=

View File

@@ -1,12 +1,12 @@
git tag v1.1.24 git tag v1.1.26
git tag bank_card/v1.1.5 git tag bank_card/v1.1.5
git tag geoip/v1.1.5 git tag geoip/v1.1.5
git tag translator/v1.1.2 git tag translator/v1.1.2
git tag copierutil/v0.0.3 git tag copierutil/v0.0.4
git tag jwtutil/v0.0.2 git tag jwtutil/v0.0.2
git tag entgo/v1.1.28 git tag entgo/v1.1.29
git tag gorm/v1.1.6 git tag gorm/v1.1.6
git push origin --tags git push origin --tags

View File

@@ -217,7 +217,7 @@ func timeMarshalJSON(t time.Time, layout string) ([]byte, error) {
} }
func ParseSlice(layout string, strings []string) ([]time.Time, error) { func ParseSlice(layout string, strings []string) ([]time.Time, error) {
times := []time.Time{} var times []time.Time
for _, raw := range strings { for _, raw := range strings {
t, err := time.Parse(layout, raw) t, err := time.Parse(layout, raw)
if err != nil { if err != nil {

View File

@@ -33,10 +33,7 @@ func UnixMilliToStringPtr(milli *int64) *string {
tm := time.UnixMilli(*milli) tm := time.UnixMilli(*milli)
// 设置默认时区 str := tm.In(GetDefaultTimeLocation()).Format(TimeLayout)
tm.In(GetDefaultTimeLocation())
str := tm.Format(TimeLayout)
return &str return &str
} }
@@ -133,10 +130,7 @@ func TimeToTimeString(tm *time.Time) *string {
return nil return nil
} }
// 设置默认时区 return trans.String(tm.In(GetDefaultTimeLocation()).Format(TimeLayout))
tm.In(GetDefaultTimeLocation())
return trans.String(tm.Format(TimeLayout))
} }
// StringDateToTime 字符串 -> 时间 // StringDateToTime 字符串 -> 时间
@@ -175,10 +169,15 @@ func TimeToDateString(tm *time.Time) *string {
return nil return nil
} }
// 设置默认时区 return trans.String(tm.In(GetDefaultTimeLocation()).Format(DateLayout))
tm.In(GetDefaultTimeLocation()) }
return trans.String(tm.Format(DateLayout)) func TimeToString(tm *time.Time, layout string) *string {
if tm == nil {
return nil
}
return trans.String(tm.Format(layout))
} }
// TimestamppbToTime timestamppb.Timestamp -> time.Time // TimestamppbToTime timestamppb.Timestamp -> time.Time

View File

@@ -149,6 +149,15 @@ func TestTimeToDateString(t *testing.T) {
assert.Nil(t, result) assert.Nil(t, result)
} }
func TestTimeToString(t *testing.T) {
now := time.Now()
fmt.Println(*TimeToString(&now, DateLayout))
fmt.Println(*TimeToString(&now, ISO8601))
fmt.Println(*TimeToString(&now, ISO8601TZHour))
fmt.Println(*TimeToString(&now, ISO8601NoTZ))
}
func TestTimestamppbToTime(t *testing.T) { func TestTimestamppbToTime(t *testing.T) {
// 测试有效输入 // 测试有效输入
timestamp := timestamppb.Now() timestamp := timestamppb.Now()