mirror of
https://github.com/duke-git/lancet.git
synced 2026-02-13 09:12:28 +08:00
feat:add betweenSeconds func (#102)
Co-authored-by: leitao <leitao@kezaihui.com>
This commit is contained in:
@@ -230,3 +230,8 @@ func EndOfYear(t time.Time) time.Time {
|
|||||||
func IsLeapYear(year int) bool {
|
func IsLeapYear(year int) bool {
|
||||||
return year%4 == 0 && (year%100 != 0 || year%400 == 0)
|
return year%4 == 0 && (year%100 != 0 || year%400 == 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func BetweenSeconds(t1 time.Time, t2 time.Time) int64 {
|
||||||
|
index := t2.Unix() - t1.Unix()
|
||||||
|
return index
|
||||||
|
}
|
||||||
|
|||||||
@@ -353,3 +353,18 @@ func ExampleIsLeapYear() {
|
|||||||
// true
|
// true
|
||||||
// false
|
// false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func ExampleBetweenSeconds() {
|
||||||
|
now := time.Now()
|
||||||
|
target := AddDay(now, 1)
|
||||||
|
|
||||||
|
now1 := time.Now()
|
||||||
|
target1 := AddDay(now, -1)
|
||||||
|
|
||||||
|
fmt.Println(BetweenSeconds(now, target))
|
||||||
|
fmt.Println(BetweenSeconds(now1, target1))
|
||||||
|
|
||||||
|
// Output:
|
||||||
|
// 86400
|
||||||
|
// -86400
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package datetime
|
package datetime
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@@ -20,6 +21,12 @@ func TestAddYear(t *testing.T) {
|
|||||||
assert.Equal(float64(-8760), diff2.Hours())
|
assert.Equal(float64(-8760), diff2.Hours())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestBetweenSeconds(t *testing.T) {
|
||||||
|
now := time.Now()
|
||||||
|
target := AddDay(now, 1)
|
||||||
|
fmt.Println(BetweenSeconds(now, target))
|
||||||
|
}
|
||||||
|
|
||||||
func TestAddDay(t *testing.T) {
|
func TestAddDay(t *testing.T) {
|
||||||
assert := internal.NewAssert(t, "TestAddDay")
|
assert := internal.NewAssert(t, "TestAddDay")
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user