forked from aws/aws-sdk-go
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
No longer needed due to custom JSON marshaling. Also replace with aws.Time(t time.Time) helper to generate a Time value pointer. Fixes aws#101
- Loading branch information
Showing
23 changed files
with
305 additions
and
371 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,57 +1,28 @@ | ||
package aws | ||
|
||
import ( | ||
"math" | ||
"strconv" | ||
"time" | ||
) | ||
import "time" | ||
|
||
// String converts a Go string into a StringValue. | ||
// String converts a Go string into a string pointer. | ||
func String(v string) *string { | ||
return &v | ||
} | ||
|
||
// Boolean converts a Go bool into a BooleanValue. | ||
// Boolean converts a Go bool into a boolean pointer. | ||
func Boolean(v bool) *bool { | ||
return &v | ||
} | ||
|
||
// Long converts a Go int64 into a LongValue. | ||
// Long converts a Go int64 into a long pointer. | ||
func Long(v int64) *int64 { | ||
return &v | ||
} | ||
|
||
// Double converts a Go float64 into a DoubleValue. | ||
// Double converts a Go float64 into a double pointer. | ||
func Double(v float64) *float64 { | ||
return &v | ||
} | ||
|
||
func NewTime(t time.Time) *Time { | ||
return &Time{t} | ||
} | ||
|
||
// A Time is a timestamp | ||
type Time struct { | ||
time.Time | ||
} | ||
|
||
// MarshalJSON marshals the timestamp as a float. | ||
func (t Time) MarshalJSON() (text []byte, err error) { | ||
n := float64(t.Time.UnixNano()) / 1e9 | ||
s := strconv.FormatFloat(n, 'f', -1, 64) | ||
return []byte(s), nil | ||
} | ||
|
||
// UnmarshalJSON unmarshals the timestamp from a float. | ||
func (t *Time) UnmarshalJSON(text []byte) error { | ||
f, err := strconv.ParseFloat(string(text), 64) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
sec := math.Floor(f) | ||
nsec := (f - sec) * 1e9 | ||
|
||
t.Time = time.Unix(int64(sec), int64(nsec)).UTC() | ||
return nil | ||
// Time converts a Go Time into a Time pointer | ||
func Time(t time.Time) *time.Time { | ||
return &t | ||
} |
This file was deleted.
Oops, something went wrong.
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
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
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
Oops, something went wrong.