Skip to content

Commit

Permalink
fix: Fix for converting old time to timestamp (#511)
Browse files Browse the repository at this point in the history
Fix for converting old time to timestamp
  • Loading branch information
Andrew Nikitin authored Jan 16, 2023
1 parent 28cb2d1 commit 7a111e0
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
5 changes: 5 additions & 0 deletions app/migrations/helpers/constant.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package helpers

const (
OldTimeFormat = "2006-01-02 15:04:05.999999999 -0700 MST"
)
8 changes: 8 additions & 0 deletions app/migrations/helpers/protobuf.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,14 @@ func MustParseFromStringTimeToGoTime(timeString string) time.Time {
}

t, err := time.Parse(time.RFC3339, timeString)
if err == nil {
return t
}
t, err = time.Parse(time.RFC3339Nano, timeString)
if err == nil {
return t
}
t, err = time.Parse(OldTimeFormat, timeString)
if err != nil {
panic(err)
}
Expand Down
20 changes: 20 additions & 0 deletions app/migrations/helpers/protobuf_test.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
package helpers

import (
"time"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)

var (
expecteRFC3339, _ = time.Parse(time.RFC3339, "2022-09-06T16:19:39Z")
expecteRFC3339Nano, _ = time.Parse(time.RFC3339Nano, "2022-09-06T16:19:39.464251406Z")
expectedOldTimeFormat, _ = time.Parse(OldTimeFormat, "2022-02-22 13:32:19.464251406 +0000 UTC")
)

var _ = DescribeTable(
"Test GenerateEd25519VerificationKey2020VerificationMaterial",
func(v1PubKey string, v2PubKey string) {
Expand All @@ -17,3 +25,15 @@ var _ = DescribeTable(
// Mainnet case
Entry("Valid: Real case", "zF7rhDBfUt9d1gJPjx7s1JXfUY7oVWkYsWCo7fztHtepn", "z6Mkta7joRuvDh7UnoESdgpr9dDUMh5LvdoECDi3WGrJoscA"),
)

var _ = DescribeTable(
"Test MustParseFromStringTimeToGoTime",
func(inputS string, outputTT time.Time) {
timeTime := MustParseFromStringTimeToGoTime(inputS)
Expect(timeTime).To(Equal(outputTT))
},

Entry("Valid: General conversion RFC3339", "2022-09-06T16:19:39Z", expecteRFC3339),
Entry("Valid: General conversion RFC3339Nano", "2022-09-06T16:19:39.464251406Z", expecteRFC3339Nano),
Entry("Valid: General conversion OldTimeFormat", "2022-02-22 13:32:19.464251406 +0000 UTC", expectedOldTimeFormat),
)

0 comments on commit 7a111e0

Please sign in to comment.