Compare commits

..

3 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
4 changed files with 21 additions and 13 deletions

View File

@@ -1,4 +1,4 @@
git tag v1.1.24
git tag v1.1.26
git tag bank_card/v1.1.5
git tag geoip/v1.1.5

View File

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

View File

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

View File

@@ -149,6 +149,15 @@ func TestTimeToDateString(t *testing.T) {
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) {
// 测试有效输入
timestamp := timestamppb.Now()