mirror of
https://github.com/duke-git/lancet.git
synced 2026-02-13 01:02:28 +08:00
refactor: update TestBetweenSeconds and ExampleBetweenSeconds
This commit is contained in:
@@ -231,6 +231,8 @@ 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)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// BetweenSeconds returns the number of seconds between two times.
|
||||||
|
// Play: todo
|
||||||
func BetweenSeconds(t1 time.Time, t2 time.Time) int64 {
|
func BetweenSeconds(t1 time.Time, t2 time.Time) int64 {
|
||||||
index := t2.Unix() - t1.Unix()
|
index := t2.Unix() - t1.Unix()
|
||||||
return index
|
return index
|
||||||
|
|||||||
@@ -355,14 +355,15 @@ func ExampleIsLeapYear() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func ExampleBetweenSeconds() {
|
func ExampleBetweenSeconds() {
|
||||||
now := time.Now()
|
today := time.Now()
|
||||||
target := AddDay(now, 1)
|
tomorrow := AddDay(today, 1)
|
||||||
|
yesterday := AddDay(today, -1)
|
||||||
|
|
||||||
now1 := time.Now()
|
result1 := BetweenSeconds(today, tomorrow)
|
||||||
target1 := AddDay(now, -1)
|
result2 := BetweenSeconds(today, yesterday)
|
||||||
|
|
||||||
fmt.Println(BetweenSeconds(now, target))
|
fmt.Println(result1)
|
||||||
fmt.Println(BetweenSeconds(now1, target1))
|
fmt.Println(result2)
|
||||||
|
|
||||||
// Output:
|
// Output:
|
||||||
// 86400
|
// 86400
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
package datetime
|
package datetime
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@@ -22,9 +21,17 @@ func TestAddYear(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestBetweenSeconds(t *testing.T) {
|
func TestBetweenSeconds(t *testing.T) {
|
||||||
now := time.Now()
|
assert := internal.NewAssert(t, "TestBetweenSeconds")
|
||||||
target := AddDay(now, 1)
|
|
||||||
fmt.Println(BetweenSeconds(now, target))
|
today := time.Now()
|
||||||
|
tomorrow := AddDay(today, 1)
|
||||||
|
yesterday := AddDay(today, -1)
|
||||||
|
|
||||||
|
result1 := BetweenSeconds(today, tomorrow)
|
||||||
|
result2 := BetweenSeconds(today, yesterday)
|
||||||
|
|
||||||
|
assert.Equal(int64(86400), result1)
|
||||||
|
assert.Equal(int64(-86400), result2)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestAddDay(t *testing.T) {
|
func TestAddDay(t *testing.T) {
|
||||||
|
|||||||
Reference in New Issue
Block a user