Commit ca24e506 by zhengqiuyun86

数组包含封装

parent f2767dca
...@@ -29,6 +29,12 @@ func Int16s(p int16) *int16 { ...@@ -29,6 +29,12 @@ func Int16s(p int16) *int16 {
func Int8s(p int8) *int8 { func Int8s(p int8) *int8 {
return &p return &p
} }
func Float64s(p float64) *float64 {
return &p
}
func Float32s(p float32) *float32 {
return &p
}
func Bytes(p byte) *byte { func Bytes(p byte) *byte {
return &p return &p
} }
......
package util package util
import "time"
func ArrayContains(array []string, e string) bool { func ArrayContains(array []string, e string) bool {
for _, v := range array { for _, v := range array {
if v == e { if v == e {
...@@ -8,3 +10,99 @@ func ArrayContains(array []string, e string) bool { ...@@ -8,3 +10,99 @@ func ArrayContains(array []string, e string) bool {
} }
return false return false
} }
func ArrayContainsUint64(array []uint64, e uint64) bool {
for _, v := range array {
if v == e {
return true
}
}
return false
}
func ArrayContainsUint32(array []uint32, e uint32) bool {
for _, v := range array {
if v == e {
return true
}
}
return false
}
func ArrayContainsUint16(array []uint16, e uint16) bool {
for _, v := range array {
if v == e {
return true
}
}
return false
}
func ArrayContainsUint8(array []uint8, e uint8) bool {
for _, v := range array {
if v == e {
return true
}
}
return false
}
func ArrayContainsInt64(array []int64, e int64) bool {
for _, v := range array {
if v == e {
return true
}
}
return false
}
func ArrayContainsInt32(array []int32, e int32) bool {
for _, v := range array {
if v == e {
return true
}
}
return false
}
func ArrayContainsInt16(array []int16, e int16) bool {
for _, v := range array {
if v == e {
return true
}
}
return false
}
func ArrayContainsInt8(array []int8, e int8) bool {
for _, v := range array {
if v == e {
return true
}
}
return false
}
func ArrayContainsFloat64(array []float64, e float64) bool {
for _, v := range array {
if v == e {
return true
}
}
return false
}
func ArrayContainsFloat32(array []float32, e float32) bool {
for _, v := range array {
if v == e {
return true
}
}
return false
}
func ArrayContainsByte(array []byte, e byte) bool {
for _, v := range array {
if v == e {
return true
}
}
return false
}
func ArrayContainsTime(array []time.Time, e time.Time) bool {
for _, v := range array {
if v == e {
return true
}
}
return false
}
package util
import (
"fmt"
"testing"
"time"
)
func TestArrayContainsInterface(t *testing.T) {
var areaIds []time.Time
areaIds = append(areaIds, PareDateTime("2022-02-09 22:09:12"))
areaIds = append(areaIds, PareDateTime("2022-03-09 22:09:12"))
areaIds = append(areaIds, PareDateTime("2022-12-09 22:09:12"))
fmt.Println(ArrayContainsTime(areaIds, PareDateTime("2022-02-10 22:09:12")))
}
...@@ -31,6 +31,11 @@ func PareDateStart(date string) time.Time { ...@@ -31,6 +31,11 @@ func PareDateStart(date string) time.Time {
return stamp return stamp
} }
func PareDateTime(dateTime string) time.Time {
stamp, _ := time.ParseInLocation(formatSimple1, dateTime, time.Local)
return stamp
}
func AddDate(date time.Time, d int) time.Time { func AddDate(date time.Time, d int) time.Time {
t := (int64)(d * 24 * 60 * 60) t := (int64)(d * 24 * 60 * 60)
return Add(date, t) return Add(date, t)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment