Skip to content

Commit

Permalink
time: Add additional timestamp format for DateTime
Browse files Browse the repository at this point in the history
Adds support for parsing DateTime timestamp formatted time similar to
RFC 3339, but without the `Z` character, nor UTC offset.

Fixes aws/aws-sdk-go-v2#1387
  • Loading branch information
jasdel committed Aug 24, 2021
1 parent 8dfe8d8 commit e0cf445
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
# Release pending

### Smithy Go Module

* `time`: Add support for parsing additional DateTime timestamp format ([#324](https://github.com/aws/smithy-go/pull/324))
* Adds support for parsing DateTime timestamp formatted time similar to RFC 3339, but without the `Z` character, nor UTC offset.
* Fixes [#1387](https://github.com/aws/aws-sdk-go-v2/issues/1387)

# Release v1.7.0

### Smithy Go Module
Expand Down
6 changes: 4 additions & 2 deletions time/time.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ import (

const (
// dateTimeFormat is a IMF-fixdate formatted RFC3339 section 5.6
dateTimeFormatInput = "2006-01-02T15:04:05.999999999Z"
dateTimeFormatOutput = "2006-01-02T15:04:05.999Z"
dateTimeFormatInput = "2006-01-02T15:04:05.999999999Z"
dateTimeFormatInputNoZ = "2006-01-02T15:04:05.999999999"
dateTimeFormatOutput = "2006-01-02T15:04:05.999Z"

// httpDateFormat is a date time defined by RFC 7231#section-7.1.1.1
// IMF-fixdate with no UTC offset.
Expand All @@ -36,6 +37,7 @@ func FormatDateTime(value time.Time) string {
func ParseDateTime(value string) (time.Time, error) {
return tryParse(value,
dateTimeFormatInput,
dateTimeFormatInputNoZ,
time.RFC3339Nano,
time.RFC3339,
)
Expand Down
6 changes: 6 additions & 0 deletions time/time_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ func TestDateTime(t *testing.T) {
time.UTC),
SymmetricString: true,
},
"no offset, no Z": {
TimeString: "1985-04-12T23:20:50.524",
TimeValue: time.Date(1985, 4, 12, 23, 20, 50, int(524*time.Millisecond),
time.UTC),
SymmetricString: false,
},
"with negative offset": {
TimeString: "1985-04-12T23:20:50.52-07:00",
TimeValue: time.Date(1985, 4, 12, 23, 20, 50, int(520*time.Millisecond),
Expand Down

0 comments on commit e0cf445

Please sign in to comment.