- 增加[验证字符串是否为时间]方法
continuous-integration/drone/push Build is passing Details
continuous-integration/drone/tag Build is passing Details

master v1.0.5
李光春 2 years ago
parent 9f8bce0361
commit d269b45582

@ -14,4 +14,20 @@
```go
go get -v -u go.dtapp.net/gotime
```
#### 使用
```go
package main
import (
"go.dtapp.net/gotime"
"testing"
)
// TestVerification 验证字符串是否为时间
func TestVerification(t *testing.T) {
t.Log(gotime.Verification("2022-02-05 00:00:00", gotime.DateTimeFormat))
}
```

@ -91,12 +91,17 @@ func Test2(t *testing.T) {
}
func TestGt(t *testing.T) {
t.Log(SetCurrentParse("2022-04-06 15:05:24").Time)
t.Log(SetCurrentParse("2022-07-29 15:05:24").Time)
t.Log(Current().Lte(SetCurrentParse("2022-07-18 17:05:24").Time))
}
func TestCompare(t *testing.T) {
t.Log("是否大于", Current().Gt(SetCurrentParse("2022-07-29 14:35:24").Time))
t.Log("是否小于", Current().Lt(SetCurrentParse("2022-07-29 14:35:24").Time))
}
func TestTaoBao(t *testing.T) {
i := 1
var i int64 = 1
for {
if i > 3 {
break
@ -112,7 +117,7 @@ func TestTaoBao(t *testing.T) {
func TestMT(t *testing.T) {
day := 1
var day int64 = 1
t.Log(day)
t.Log(Current().BeforeHour(24 * day).Format())
t.Log(Current().BeforeHour(24 * (day - 1)).Format())

@ -0,0 +1,16 @@
package gotime
import "time"
// Verification 验证字符串是否为时间
func Verification(str, layout string) (resp time.Time, err error) {
loc, err := time.LoadLocation("Asia/Shanghai")
if err != nil {
return time.Time{}, err
}
location, err := time.ParseInLocation(layout, str, loc)
if err != nil {
return time.Time{}, err
}
return location, nil
}

@ -0,0 +1,7 @@
package gotime
import "testing"
func TestVerification(t *testing.T) {
t.Log(Verification("2022-02-05 00:00:00", DateTimeFormat))
}

@ -1,3 +1,3 @@
package gotime
const Version = "1.0.4"
const Version = "1.0.5"

@ -0,0 +1,13 @@
package gotime
import "testing"
func TestVersion(t *testing.T) {
t.Log(Version)
}
func BenchmarkVersion(b *testing.B) {
for i := 0; i < b.N; i++ {
b.Log(Version)
}
}
Loading…
Cancel
Save