Browse Source

修改字符转换

master v0.7.1
guzeng 9 months ago
parent
commit
4afc8e0f8f
7 changed files with 35 additions and 20 deletions
  1. +0
    -0
      math.go
  2. +13
    -10
      math_test.go
  3. +7
    -7
      string.go
  4. +7
    -0
      string_test.go
  5. +0
    -0
      system.go
  6. +0
    -0
      time.go
  7. +8
    -3
      time_test.go

+ 0
- 0
math.go View File


+ 13
- 10
math_test.go View File

@ -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)
// }

+ 7
- 7
string.go View File

@ -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"
}
func TencentCloudImageCompress(imgUrl, ratio string) string {
return imgUrl + "?imageMogr2/thumbnail/" + ratio + "x/interlace/1"
}

+ 7
- 0
string_test.go View File

@ -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"))
}

+ 0
- 0
system.go View File


+ 0
- 0
time.go View File


+ 8
- 3
time_test.go View File

@ -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())
}

Loading…
Cancel
Save