Skip to content

Commit

Permalink
add String to dynamodbattribute.UnixTime (#4504)
Browse files Browse the repository at this point in the history
This change adds a String method to dynamodbattribute.UnixTime, so that
when structs with this field get logged it prints a human readable time.
  • Loading branch information
zendes committed Aug 10, 2022
1 parent 36e99e2 commit d9e960f
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG_PENDING.md
@@ -1,5 +1,7 @@
### SDK Features

### SDK Enhancements
* `service/dynamodb/dynamodbattribute`: Add String method to UnixTime
* Adds a `String` method to `UnixTime`, so that when structs with this field get logged it prints a human readable time.

### SDK Bugs
5 changes: 5 additions & 0 deletions service/dynamodb/dynamodbattribute/encode.go
Expand Up @@ -23,6 +23,11 @@ import (
// January 1, 0001 UTC, and January 1, 0001 UTC.
type UnixTime time.Time

// String calls the underlying time.Time.String to return a human readable representation
func (e UnixTime) String() string {
return time.Time(e).String()
}

// MarshalDynamoDBAttributeValue implements the Marshaler interface so that
// the UnixTime can be marshaled from to a DynamoDB AttributeValue number
// value encoded in the number of seconds since January 1, 1970 UTC.
Expand Down
8 changes: 8 additions & 0 deletions service/dynamodb/dynamodbattribute/encode_test.go
Expand Up @@ -11,6 +11,14 @@ import (
"github.com/aws/aws-sdk-go/service/dynamodb"
)

func TestString(t *testing.T) {
gotime := time.Date(2016, time.May, 03, 17, 06, 26, 0, time.UTC)
ddbtime := UnixTime(gotime)
if fmt.Sprint(gotime) != fmt.Sprint(ddbtime) {
t.Error("UnixTime.String not equal to time.Time.String")
}
}

func TestMarshalErrorTypes(t *testing.T) {
var _ awserr.Error = (*InvalidMarshalError)(nil)
var _ awserr.Error = (*unsupportedMarshalTypeError)(nil)
Expand Down

0 comments on commit d9e960f

Please sign in to comment.