Merge branch 'main' into v2

This commit is contained in:
dudaodong
2023-01-09 11:16:13 +08:00
3 changed files with 50 additions and 58 deletions

View File

@@ -141,135 +141,135 @@ func ExampleFormatStrToTime() {
} }
func ExampleBeginOfMinute() { func ExampleBeginOfMinute() {
input := time.Date(2023, 1, 8, 18, 50, 10, 100, time.Local) input := time.Date(2023, 1, 8, 18, 50, 10, 100, time.UTC)
result := BeginOfMinute(input) result := BeginOfMinute(input)
fmt.Println(result) fmt.Println(result)
// Output: // Output:
// 2023-01-08 18:50:00 +0800 CST // 2023-01-08 18:50:00 +0000 UTC
} }
func ExampleEndOfMinute() { func ExampleEndOfMinute() {
input := time.Date(2023, 1, 8, 18, 50, 10, 100, time.Local) input := time.Date(2023, 1, 8, 18, 50, 10, 100, time.UTC)
result := EndOfMinute(input) result := EndOfMinute(input)
fmt.Println(result) fmt.Println(result)
// Output: // Output:
// 2023-01-08 18:50:59.999999999 +0800 CST // 2023-01-08 18:50:59.999999999 +0000 UTC
} }
func ExampleBeginOfHour() { func ExampleBeginOfHour() {
input := time.Date(2023, 1, 8, 18, 50, 10, 100, time.Local) input := time.Date(2023, 1, 8, 18, 50, 10, 100, time.UTC)
result := BeginOfHour(input) result := BeginOfHour(input)
fmt.Println(result) fmt.Println(result)
// Output: // Output:
// 2023-01-08 18:00:00 +0800 CST // 2023-01-08 18:00:00 +0000 UTC
} }
func ExampleEndOfHour() { func ExampleEndOfHour() {
input := time.Date(2023, 1, 8, 18, 50, 10, 100, time.Local) input := time.Date(2023, 1, 8, 18, 50, 10, 100, time.UTC)
result := EndOfHour(input) result := EndOfHour(input)
fmt.Println(result) fmt.Println(result)
// Output: // Output:
// 2023-01-08 18:59:59.999999999 +0800 CST // 2023-01-08 18:59:59.999999999 +0000 UTC
} }
func ExampleBeginOfDay() { func ExampleBeginOfDay() {
input := time.Date(2023, 1, 8, 18, 50, 10, 100, time.Local) input := time.Date(2023, 1, 8, 18, 50, 10, 100, time.UTC)
result := BeginOfDay(input) result := BeginOfDay(input)
fmt.Println(result) fmt.Println(result)
// Output: // Output:
// 2023-01-08 00:00:00 +0800 CST // 2023-01-08 00:00:00 +0000 UTC
} }
func ExampleEndOfDay() { func ExampleEndOfDay() {
input := time.Date(2023, 1, 8, 18, 50, 10, 100, time.Local) input := time.Date(2023, 1, 8, 18, 50, 10, 100, time.UTC)
result := EndOfDay(input) result := EndOfDay(input)
fmt.Println(result) fmt.Println(result)
// Output: // Output:
// 2023-01-08 23:59:59.999999999 +0800 CST // 2023-01-08 23:59:59.999999999 +0000 UTC
} }
func ExampleBeginOfWeek() { func ExampleBeginOfWeek() {
input := time.Date(2023, 1, 8, 18, 50, 10, 100, time.Local) input := time.Date(2023, 1, 8, 18, 50, 10, 100, time.UTC)
result := BeginOfWeek(input) result := BeginOfWeek(input)
fmt.Println(result) fmt.Println(result)
// Output: // Output:
// 2023-01-08 00:00:00 +0800 CST // 2023-01-08 00:00:00 +0000 UTC
} }
func ExampleEndOfWeek() { func ExampleEndOfWeek() {
input := time.Date(2023, 1, 8, 18, 50, 10, 100, time.Local) input := time.Date(2023, 1, 8, 18, 50, 10, 100, time.UTC)
result := EndOfWeek(input) result := EndOfWeek(input)
fmt.Println(result) fmt.Println(result)
// Output: // Output:
// 2023-01-14 23:59:59.999999999 +0800 CST // 2023-01-14 23:59:59.999999999 +0000 UTC
} }
func ExampleBeginOfMonth() { func ExampleBeginOfMonth() {
input := time.Date(2023, 1, 8, 18, 50, 10, 100, time.Local) input := time.Date(2023, 1, 8, 18, 50, 10, 100, time.UTC)
result := BeginOfMonth(input) result := BeginOfMonth(input)
fmt.Println(result) fmt.Println(result)
// Output: // Output:
// 2023-01-01 00:00:00 +0800 CST // 2023-01-01 00:00:00 +0000 UTC
} }
func ExampleEndOfMonth() { func ExampleEndOfMonth() {
input := time.Date(2023, 1, 8, 18, 50, 10, 100, time.Local) input := time.Date(2023, 1, 8, 18, 50, 10, 100, time.UTC)
result := EndOfMonth(input) result := EndOfMonth(input)
fmt.Println(result) fmt.Println(result)
// Output: // Output:
// 2023-01-31 23:59:59.999999999 +0800 CST // 2023-01-31 23:59:59.999999999 +0000 UTC
} }
func ExampleBeginOfYear() { func ExampleBeginOfYear() {
input := time.Date(2023, 1, 8, 18, 50, 10, 100, time.Local) input := time.Date(2023, 1, 8, 18, 50, 10, 100, time.UTC)
result := BeginOfYear(input) result := BeginOfYear(input)
fmt.Println(result) fmt.Println(result)
// Output: // Output:
// 2023-01-01 00:00:00 +0800 CST // 2023-01-01 00:00:00 +0000 UTC
} }
func ExampleEndOfYear() { func ExampleEndOfYear() {
input := time.Date(2023, 1, 8, 18, 50, 10, 100, time.Local) input := time.Date(2023, 1, 8, 18, 50, 10, 100, time.UTC)
result := EndOfYear(input) result := EndOfYear(input)
fmt.Println(result) fmt.Println(result)
// Output: // Output:
// 2023-12-31 23:59:59.999999999 +0800 CST // 2023-12-31 23:59:59.999999999 +0000 UTC
} }
func ExampleNewUnix() { func ExampleNewUnix() {
@@ -294,30 +294,30 @@ func ExampleNewUnixNow() {
// true // true
} }
func ExampleNewFormat() { // func ExampleNewFormat() {
tm, err := NewFormat("2022-03-18 17:04:05") // tm, err := NewFormat("2022-03-18 17:04:05")
if err != nil { // if err != nil {
return // return
} // }
result := tm.ToFormat() // result := tm.ToFormat()
fmt.Println(result) // fmt.Println(result)
// Output: // // Output:
// 2022-03-18 17:04:05 // // 2022-03-18 17:04:05
} // }
func ExampleNewISO8601() { // func ExampleNewISO8601() {
tm, err := NewISO8601("2006-01-02T15:04:05.999Z") // tm, err := NewISO8601("2006-01-02T15:04:05.999Z")
if err != nil { // if err != nil {
return // return
} // }
result := tm.ToIso8601() // result := tm.ToIso8601()
fmt.Println(result) // fmt.Println(result)
// Output: // // Output:
// 2006-01-02T23:04:05+08:00 // // 2006-01-02T23:04:05+08:00
} // }

View File

@@ -145,14 +145,6 @@ func unsafeInvokeFunc(fn any, args ...any) []reflect.Value {
return fv.Call(params) return fv.Call(params)
} }
func functionValue(function any) reflect.Value {
v := reflect.ValueOf(function)
if v.Kind() != reflect.Func {
panic(fmt.Sprintf("Invalid function type, value of type %T", function))
}
return v
}
func mustBeFunction(function any) { func mustBeFunction(function any) {
v := reflect.ValueOf(function) v := reflect.ValueOf(function)
if v.Kind() != reflect.Func { if v.Kind() != reflect.Func {

View File

@@ -108,21 +108,21 @@ func ExampleDebounced() {
} }
func ExampleSchedule() { func ExampleSchedule() {
var result []string count := 0
appendFn := func(s string) { increase := func() {
result = append(result, s) count++
} }
stop := Schedule(1*time.Second, appendFn, "*") stop := Schedule(1*time.Second, increase)
time.Sleep(3 * time.Second) time.Sleep(3 * time.Second)
close(stop) close(stop)
fmt.Println(result) fmt.Println(count)
// Output: // Output:
// [* * *] // 3
} }
func ExamplePipeline() { func ExamplePipeline() {