Skip to content

Commit

Permalink
Add Now() utility function
Browse files Browse the repository at this point in the history
Signed-off-by: Lorenzo <[email protected]>
  • Loading branch information
lorenzodonini committed Oct 31, 2023
1 parent bc0ceee commit 0eb87c1
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 0 deletions.
5 changes: 5 additions & 0 deletions ocpp1.6/types/datetime.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ func NewDateTime(time time.Time) *DateTime {
return &DateTime{Time: time}
}

// Creates a new DateTime struct, containing a time.Now() value.
func Now() *DateTime {
return &DateTime{Time: time.Now()}
}

func null(b []byte) bool {
if len(b) != 4 {
return false
Expand Down
6 changes: 6 additions & 0 deletions ocpp1.6_test/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,3 +176,9 @@ func (suite *OcppV16TestSuite) TestMarshalDateTime() {
suite.Equal(dt.ExpectedFormattedString, formatted)
}
}

func (suite *OcppV16TestSuite) TestNowDateTime() {
now := types.Now()
suite.NotNil(now)
suite.True(time.Now().Sub(now.Time) < 1*time.Second)
}
5 changes: 5 additions & 0 deletions ocpp2.0.1/types/datetime.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ func NewDateTime(time time.Time) *DateTime {
return &DateTime{Time: time}
}

// Creates a new DateTime struct, containing a time.Now() value.
func Now() *DateTime {
return &DateTime{Time: time.Now()}
}

func null(b []byte) bool {
if len(b) != 4 {
return false
Expand Down
6 changes: 6 additions & 0 deletions ocpp2.0.1_test/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -338,3 +338,9 @@ func (suite *OcppV2TestSuite) TestMarshalDateTime() {
suite.Equal(dt.ExpectedFormattedString, formatted)
}
}

func (suite *OcppV2TestSuite) TestNowDateTime() {
now := types.Now()
suite.NotNil(now)
suite.True(time.Now().Sub(now.Time) < 1*time.Second)
}

0 comments on commit 0eb87c1

Please sign in to comment.