-
Notifications
You must be signed in to change notification settings - Fork 3
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 #12 from launchdarkly/eb/ch64206/time-type
add ldtime package for time helpers
- Loading branch information
Showing
5 changed files
with
34 additions
and
5 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,2 @@ | ||
// Package ldtime contains time-related types and functions used by LaunchDarkly packages. | ||
package ldtime |
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,17 @@ | ||
package ldtime | ||
|
||
import "time" | ||
|
||
// UnixMillisecondTime is a millisecond timestamp starting from the Unix epoch. | ||
type UnixMillisecondTime uint64 | ||
|
||
// UnixMillisFromTime converts a Time value into UnixMillisecondTime. | ||
func UnixMillisFromTime(t time.Time) UnixMillisecondTime { | ||
ms := time.Duration(t.UnixNano()) / time.Millisecond | ||
return UnixMillisecondTime(ms) | ||
} | ||
|
||
// UnixMillisNow returns the current date/time as a UnixMillisecondTime. | ||
func UnixMillisNow() UnixMillisecondTime { | ||
return UnixMillisFromTime(time.Now()) | ||
} |
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,14 @@ | ||
package ldtime | ||
|
||
import ( | ||
"testing" | ||
"time" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestUnixMillisFromTime(t *testing.T) { | ||
tt := time.Date(1970, time.January, 1, 0, 1, 2, 0, time.UTC) | ||
ut := UnixMillisFromTime(tt) | ||
assert.Equal(t, uint64(62000), uint64(ut)) | ||
} |
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,7 +1,4 @@ | ||
// Package ldcommon is the base package for commonly used Go SDK types and functions. | ||
// | ||
// Currently there are no types in this package; they are all in subpackages such as ldvalue. | ||
// In a future version, this package will contain the types that are most commonly needed | ||
// when using the SDK, such as User. The subpackages contain types that applications are | ||
// less likely to need (and that do not reference anything in the main package), such as Value. | ||
package ldcommon |