Skip to content

Commit

Permalink
feat: add time.Now() pointer
Browse files Browse the repository at this point in the history
  • Loading branch information
CC11001100 committed May 30, 2023
1 parent 7778f57 commit c12bc2e
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 1 deletion.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,10 @@ func main() {
v2 = 0
orDefault := pointer.FromPointerOrDefault(v3, 1)
fmt.Println(orDefault) // Output: 0

// 返回当前时间的指针
nowPointer := pointer.Now()
fmt.Println(nowPointer) // Output: 2023-05-30 11:46:20.3695476 +0800 CST m=+0.003922101
}
```

Expand Down
4 changes: 4 additions & 0 deletions README_en.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,10 @@ func main() {
v2 = 0
orDefault := pointer.FromPointerOrDefault(v3, 1)
fmt.Println(orDefault) // Output: 0

// return time.Now() pointer
nowPointer := pointer.Now()
fmt.Println(nowPointer) // Output: 2023-05-30 11:46:20.3695476 +0800 CST m=+0.003922101
}
```

Expand Down
4 changes: 4 additions & 0 deletions example/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,8 @@ func main() {
v2 = 0
orDefault := pointer.FromPointerOrDefault(v3, 1)
fmt.Println(orDefault) // Output: 0

// 返回当前时间的指针
nowPointer := pointer.Now()
fmt.Println(nowPointer) // Output: 2023-05-30 11:46:20.3695476 +0800 CST m=+0.003922101
}
10 changes: 9 additions & 1 deletion pointer.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package pointer

import reflectutils "github.com/golang-infrastructure/go-reflect-utils"
import (
reflectutils "github.com/golang-infrastructure/go-reflect-utils"
"time"
)

// TruePointer 返回一个布尔指针,其值为true
func TruePointer() *bool {
Expand All @@ -14,6 +17,11 @@ func FalsePointer() *bool {
return &b
}

// Now 返回当前时间的指针
func Now() *time.Time {
return ToPointer(time.Now())
}

// ToPointer 将布尔变量转换为布尔指针
func ToPointer[T any](value T) *T {
return &value
Expand Down

0 comments on commit c12bc2e

Please sign in to comment.