Skip to content

Commit

Permalink
Support decimal precision timestamps (#3376)
Browse files Browse the repository at this point in the history
Adds support for decimal precision UNIX timestamps up to thousandths of a second
  • Loading branch information
skmcgrail authored Jun 16, 2020
1 parent d8ca091 commit 0909baa
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG_PENDING.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
### SDK Features

### SDK Enhancements
* `private/protocol`: Adds support for decimal precision UNIX timestamps up to thousandths of a second ([#3376](https://github.com/aws/aws-sdk-go/pull/3376))

### SDK Bugs
3 changes: 2 additions & 1 deletion private/protocol/timestamp.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ func FormatTime(name string, t time.Time) string {
case ISO8601TimeFormatName:
return t.Format(ISO8601OutputTimeFormat)
case UnixTimeFormatName:
return strconv.FormatInt(t.Unix(), 10)
ms := t.UnixNano() / int64(time.Millisecond)
return strconv.FormatFloat(float64(ms)/1e3, 'f', -1, 64)
default:
panic("unknown timestamp format name, " + name)
}
Expand Down
9 changes: 7 additions & 2 deletions private/protocol/timestamp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ func TestFormatTime(t *testing.T) {
"UnixTest1": {
formatName: UnixTimeFormatName,
expectedOutput: "946845296",
input: time.Date(2000, time.January, 2, 20, 34, 56, 0, time.UTC),
},
"UnixTest2": {
formatName: UnixTimeFormatName,
expectedOutput: "946845296.123",
input: time.Date(2000, time.January, 2, 20, 34, 56, .123e9, time.UTC),
},
"ISO8601Test1": {
Expand All @@ -32,8 +37,8 @@ func TestFormatTime(t *testing.T) {

for name, c := range cases {
t.Run(name, func(t *testing.T) {
if FormatTime(c.formatName, c.input) != c.expectedOutput {
t.Errorf("input and output time don't match for %s format ", c.formatName)
if e, a := c.expectedOutput, FormatTime(c.formatName, c.input); e != a {
t.Errorf("expected %s, got %s for %s format ", e, a, c.formatName)
}
})
}
Expand Down

0 comments on commit 0909baa

Please sign in to comment.