Skip to content

Commit

Permalink
add ptr.Time
Browse files Browse the repository at this point in the history
  • Loading branch information
junedev committed Feb 16, 2022
1 parent 0befde4 commit eedf821
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
7 changes: 7 additions & 0 deletions ptr/ptr.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
// To fill these structs with dummy values for tests you need to create pointers to values with primitive types (see example).
package ptr

import "time"

// String returns a pointer to the given string value.
func String(v string) *string {
return &v
Expand Down Expand Up @@ -32,3 +34,8 @@ func Float64(v float64) *float64 {
func Bool(v bool) *bool {
return &v
}

// Time returns a pointer to a given time.Time value.
func Time(v time.Time) *time.Time {
return &v
}
7 changes: 7 additions & 0 deletions ptr/ptr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package ptr_test

import (
"testing"
"time"

"github.com/fastbill/go-tiny-helpers/v2/ptr"
"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -36,3 +37,9 @@ func TestBool(t *testing.T) {
result := ptr.Bool(true)
assert.True(t, *result)
}

func TestTime(t *testing.T) {
now := time.Now()
result := ptr.Time(now)
assert.Equal(t, now, *result)
}

0 comments on commit eedf821

Please sign in to comment.