diff options
author | appilon <apilon@hashicorp.com> | 2019-02-27 16:43:31 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-02-27 16:43:31 -0500 |
commit | 844b5a68d8af4791755b8f0ad293cc99f5959183 (patch) | |
tree | 255c250a5c9d4801c74092d33b7337d8c14438ff /vendor/github.com/aws/aws-sdk-go/private/protocol/timestamp.go | |
parent | 303b299eeb6b06e939e35905e4b34cb410dd9dc3 (diff) | |
parent | 15c0b25d011f37e7c20aeca9eaf461f78285b8d9 (diff) | |
download | terraform-provider-statuscake-844b5a68d8af4791755b8f0ad293cc99f5959183.tar.gz terraform-provider-statuscake-844b5a68d8af4791755b8f0ad293cc99f5959183.tar.zst terraform-provider-statuscake-844b5a68d8af4791755b8f0ad293cc99f5959183.zip |
Merge pull request #27 from terraform-providers/go-modules-2019-02-22
[MODULES] Switch to Go Modules
Diffstat (limited to 'vendor/github.com/aws/aws-sdk-go/private/protocol/timestamp.go')
-rw-r--r-- | vendor/github.com/aws/aws-sdk-go/private/protocol/timestamp.go | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/vendor/github.com/aws/aws-sdk-go/private/protocol/timestamp.go b/vendor/github.com/aws/aws-sdk-go/private/protocol/timestamp.go new file mode 100644 index 0000000..b7ed6c6 --- /dev/null +++ b/vendor/github.com/aws/aws-sdk-go/private/protocol/timestamp.go | |||
@@ -0,0 +1,72 @@ | |||
1 | package protocol | ||
2 | |||
3 | import ( | ||
4 | "strconv" | ||
5 | "time" | ||
6 | ) | ||
7 | |||
8 | // Names of time formats supported by the SDK | ||
9 | const ( | ||
10 | RFC822TimeFormatName = "rfc822" | ||
11 | ISO8601TimeFormatName = "iso8601" | ||
12 | UnixTimeFormatName = "unixTimestamp" | ||
13 | ) | ||
14 | |||
15 | // Time formats supported by the SDK | ||
16 | const ( | ||
17 | // RFC 7231#section-7.1.1.1 timetamp format. e.g Tue, 29 Apr 2014 18:30:38 GMT | ||
18 | RFC822TimeFormat = "Mon, 2 Jan 2006 15:04:05 GMT" | ||
19 | |||
20 | // RFC3339 a subset of the ISO8601 timestamp format. e.g 2014-04-29T18:30:38Z | ||
21 | ISO8601TimeFormat = "2006-01-02T15:04:05Z" | ||
22 | ) | ||
23 | |||
24 | // IsKnownTimestampFormat returns if the timestamp format name | ||
25 | // is know to the SDK's protocols. | ||
26 | func IsKnownTimestampFormat(name string) bool { | ||
27 | switch name { | ||
28 | case RFC822TimeFormatName: | ||
29 | fallthrough | ||
30 | case ISO8601TimeFormatName: | ||
31 | fallthrough | ||
32 | case UnixTimeFormatName: | ||
33 | return true | ||
34 | default: | ||
35 | return false | ||
36 | } | ||
37 | } | ||
38 | |||
39 | // FormatTime returns a string value of the time. | ||
40 | func FormatTime(name string, t time.Time) string { | ||
41 | t = t.UTC() | ||
42 | |||
43 | switch name { | ||
44 | case RFC822TimeFormatName: | ||
45 | return t.Format(RFC822TimeFormat) | ||
46 | case ISO8601TimeFormatName: | ||
47 | return t.Format(ISO8601TimeFormat) | ||
48 | case UnixTimeFormatName: | ||
49 | return strconv.FormatInt(t.Unix(), 10) | ||
50 | default: | ||
51 | panic("unknown timestamp format name, " + name) | ||
52 | } | ||
53 | } | ||
54 | |||
55 | // ParseTime attempts to parse the time given the format. Returns | ||
56 | // the time if it was able to be parsed, and fails otherwise. | ||
57 | func ParseTime(formatName, value string) (time.Time, error) { | ||
58 | switch formatName { | ||
59 | case RFC822TimeFormatName: | ||
60 | return time.Parse(RFC822TimeFormat, value) | ||
61 | case ISO8601TimeFormatName: | ||
62 | return time.Parse(ISO8601TimeFormat, value) | ||
63 | case UnixTimeFormatName: | ||
64 | v, err := strconv.ParseFloat(value, 64) | ||
65 | if err != nil { | ||
66 | return time.Time{}, err | ||
67 | } | ||
68 | return time.Unix(int64(v), 0), nil | ||
69 | default: | ||
70 | panic("unknown timestamp format name, " + formatName) | ||
71 | } | ||
72 | } | ||