-
Notifications
You must be signed in to change notification settings - Fork 815
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #657 from 99designs/add-format-iso8601-func
Add a function to format times compatible with aws sdks
- Loading branch information
Showing
5 changed files
with
43 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package iso8601 | ||
|
||
import "time" | ||
|
||
// Format outputs an ISO-8601 datetime string from the given time, | ||
// in a format compatible with all of the AWS SDKs | ||
func Format(t time.Time) string { | ||
return t.UTC().Format(time.RFC3339) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package iso8601 | ||
|
||
import ( | ||
"testing" | ||
"time" | ||
) | ||
|
||
func TestFormat(t *testing.T) { | ||
input, _ := time.Parse(time.RFC3339, "2009-02-04T21:00:57-08:00") | ||
want := "2009-02-05T05:00:57Z" | ||
result := Format(input) | ||
if result != want { | ||
t.Errorf("expected %s for %q got %s", want, input, result) | ||
} | ||
} | ||
|
||
func TestFormatForIssue655(t *testing.T) { | ||
input, _ := time.Parse(time.RFC3339, "2020-09-10T18:16:52+02:00") | ||
want := "2020-09-10T16:16:52Z" | ||
result := Format(input) | ||
if result != want { | ||
t.Errorf("expected %s for %q got %s", want, input, result) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters