-
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.
Merge pull request #54 from radekg/hybrid-time-utils
Add utility functions to simplify working with hybrid time
- Loading branch information
Showing
3 changed files
with
55 additions
and
0 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
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,36 @@ | ||
package hybridtime | ||
|
||
import ( | ||
"testing" | ||
"time" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestHybridTime(t *testing.T) { | ||
|
||
t.Run("it=handles fixed point in time", func(tt *testing.T) { | ||
// this is a fixed server clock pointing at exactly '2021-12-03 00:27:34 +0000 UTC': | ||
fixedPointInTime := uint64(6711260180246810624) | ||
resultTime := UnixTimeFromHT(fixedPointInTime) | ||
assert.Equal(tt, "2021-12-03 00:27:34 +0000 UTC", resultTime.UTC().String()) | ||
}) | ||
|
||
t.Run("it=converts times correctly", func(tt *testing.T) { | ||
now := time.Now().UTC() | ||
resultHT := UnixTimeToHT(now) | ||
resultTime := UnixTimeFromHT(resultHT) | ||
assert.Equal(tt, now.Unix(), resultTime.Unix()) | ||
}) | ||
|
||
t.Run("it=handles add and substract", func(tt *testing.T) { | ||
now := time.Now().UTC() | ||
resultHT := UnixTimeToHT(now) | ||
afterAddHT := AddDuration(resultHT, time.Duration(time.Hour*48)) | ||
afterSubstractHT := SubstractDuration(afterAddHT, time.Duration(time.Hour*48)) | ||
resultTime := UnixTimeFromHT(afterSubstractHT) | ||
assert.Equal(tt, now.Unix(), resultTime.Unix()) | ||
|
||
}) | ||
|
||
} |