From 4afc8e0f8fd9530e922a0901f0c00a858c808ed8 Mon Sep 17 00:00:00 2001 From: guzeng Date: Sat, 29 Jul 2023 11:12:02 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=AD=97=E7=AC=A6=E8=BD=AC?= =?UTF-8?q?=E6=8D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- math.go | 0 math_test.go | 23 +++++++++++++---------- string.go | 14 +++++++------- string_test.go | 7 +++++++ system.go | 0 time.go | 0 time_test.go | 11 ++++++++--- 7 files changed, 35 insertions(+), 20 deletions(-) mode change 100755 => 100644 math.go mode change 100755 => 100644 string.go mode change 100755 => 100644 string_test.go mode change 100755 => 100644 system.go mode change 100755 => 100644 time.go mode change 100755 => 100644 time_test.go diff --git a/math.go b/math.go old mode 100755 new mode 100644 diff --git a/math_test.go b/math_test.go index 9077fff..fd34180 100644 --- a/math_test.go +++ b/math_test.go @@ -1,6 +1,7 @@ package helper import ( + "math" "strings" "testing" ) @@ -41,16 +42,18 @@ func Test_FloatQuo(t *testing.T) { str2 := "7" ret := FloatQuo(str1, str2, 3) t.Log(ret) -} - -func Test_TenToHex(t *testing.T) { - str1 := 10664 - ret := TenToHex(str1) + ret = math.Ceil(FloatQuo(4500, 3600)) t.Log(ret) } -func Test_HexToTen(t *testing.T) { - str := "29B79F0D" - ret, err := HexToTen(str) - t.Log(ret, err) -} +// func Test_TenToHex(t *testing.T) { +// str1 := 10664 +// ret := TenToHex(str1) +// t.Log(ret) +// } + +// func Test_HexToTen(t *testing.T) { +// str := "29B79F0D" +// ret, err := HexToTen(str) +// t.Log(ret, err) +// } diff --git a/string.go b/string.go old mode 100755 new mode 100644 index fd986e0..7c3df6b --- a/string.go +++ b/string.go @@ -31,6 +31,8 @@ func ToString(v interface{}) string { value = string(v.([]uint8)) // case []byte: // value = string(v.([]byte)) + case time.Time: + value = v.(time.Time).Format("2006-01-02 15:04:05") case interface{}: value = v.(string) case nil: @@ -141,7 +143,7 @@ func ToInt64(inter interface{}) int64 { return value } -//生成随机字符串 +// 生成随机字符串 func GetRandomString(length int) string { str := "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" bytes := []byte(str) @@ -153,7 +155,7 @@ func GetRandomString(length int) string { return string(result) } -//生成随机数字 +// 生成随机数字 func GetRandomNumber(length int) string { str := "0123456789" bytes := []byte(str) @@ -272,7 +274,6 @@ func UrlJoin(host, url string) string { return StringJoin(host, url) } - /** * 去除字符串的html标签 * @2021/10/20 @@ -296,12 +297,11 @@ func TrimHtml(src string) string { return strings.TrimSpace(src) } - /** * 腾讯云图片压缩 * @2021/11/19 * @linsen */ -func TencentCloudImageCompress(imgUrl,ratio string)string{ - return imgUrl + "?imageMogr2/thumbnail/"+ ratio +"x/interlace/1" -} \ No newline at end of file +func TencentCloudImageCompress(imgUrl, ratio string) string { + return imgUrl + "?imageMogr2/thumbnail/" + ratio + "x/interlace/1" +} diff --git a/string_test.go b/string_test.go old mode 100755 new mode 100644 index 513e889..24164f9 --- a/string_test.go +++ b/string_test.go @@ -2,6 +2,7 @@ package helper import ( "fmt" + "strings" "testing" ) @@ -53,3 +54,9 @@ func Test_ToInt(t *testing.T) { ret := ToInt(str) t.Log(ret) } +func Test_IsInStringArray(t *testing.T) { + var s string = "1,19,37,220,351,466,585,655,801,820,933,1046,1168,1263,1375,1532,1709,1827,1965,1977,1988,2003,2011,2017,2025,2035,2041,2050,2056,2065,2070,2077,2082,2091,2123,2146,2150,2156,2162,2291,2323,2367,2572,2670,2816,2898,3022,3126,3178,3206,3325,3716,3738" + arr := strings.Split(s, ",") + + t.Log(IsInStringArray(arr, "351")) +} diff --git a/system.go b/system.go old mode 100755 new mode 100644 diff --git a/time.go b/time.go old mode 100755 new mode 100644 diff --git a/time_test.go b/time_test.go old mode 100755 new mode 100644 index 7282478..06ae872 --- a/time_test.go +++ b/time_test.go @@ -2,6 +2,7 @@ package helper import ( "testing" + "time" // "time" ) @@ -29,9 +30,13 @@ import ( func Test_GetTodayStartTimeStamp(t *testing.T) { - for i := 0; i < 1000; i++ { - ret := GetTodayEndTimeStamp() - t.Log(ret) + reserve_date := "2023-05-15" + reserveTime, err := time.ParseInLocation("2006-01-02", reserve_date, time.Local) + if err != nil { + t.Log("err:", err) } + // 今天0点的时间戳 + + t.Log(reserveTime.Unix()) }