Skip to content

Commit

Permalink
fix(gomobile): GOARCH=386 timestamp format
Browse files Browse the repository at this point in the history
Signed-off-by: Godefroy Ponsinet <godefroy.ponsinet@outlook.com>
  • Loading branch information
90dy committed Dec 12, 2018
1 parent 824e312 commit c3c19a8
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 11 deletions.
8 changes: 4 additions & 4 deletions core/api/node/graphql/models/scalar.go
Expand Up @@ -9,8 +9,8 @@ import (
"strconv"
"time"

"berty.tech/core/sql"
"github.com/99designs/gqlgen/graphql"
sqlcipher "github.com/xeodou/go-sqlcipher"
)

// type ID struct {
Expand Down Expand Up @@ -74,7 +74,7 @@ func UnmarshalString(v interface{}) (string, error) {

func MarshalTime(t time.Time) graphql.Marshaler {
return graphql.WriterFunc(func(w io.Writer) {
_, err := io.WriteString(w, strconv.Quote(t.Format(sqlcipher.SQLiteTimestampFormats[0])))
_, err := io.WriteString(w, strconv.Quote(t.Format(sql.TimestampFormat)))
if err != nil {
logger().Error(err.Error())
}
Expand All @@ -90,9 +90,9 @@ func UnmarshalTime(v interface{}) (time.Time, error) {
if len(v) == 0 {
return time.Time{}, nil
}
return time.Parse(sqlcipher.SQLiteTimestampFormats[0], v)
return time.Parse(sql.TimestampFormat, v)
default:
return time.Time{}, errors.New("time should be formatted as " + sqlcipher.SQLiteTimestampFormats[0])
return time.Time{}, errors.New("time should be formatted as " + sql.TimestampFormat)
}
return graphql.UnmarshalTime(v)
}
Expand Down
14 changes: 7 additions & 7 deletions core/api/node/graphql/resolver.go
Expand Up @@ -16,8 +16,8 @@ import (
"berty.tech/core/entity"
"berty.tech/core/network"
"berty.tech/core/pkg/deviceinfo"
"berty.tech/core/sql"
"github.com/golang/protobuf/protoc-gen-go/descriptor"
sqlcipher "github.com/xeodou/go-sqlcipher"
"go.uber.org/zap"
)

Expand Down Expand Up @@ -354,9 +354,9 @@ func (r *queryResolver) EventList(ctx context.Context, filter *p2p.Event, rawOnl
case "", "id":
cursor = n.ID
case "created_at":
cursor = n.CreatedAt.Format(sqlcipher.SQLiteTimestampFormats[0])
cursor = n.CreatedAt.Format(sql.TimestampFormat)
case "updated_at":
cursor = n.UpdatedAt.Format(sqlcipher.SQLiteTimestampFormats[0])
cursor = n.UpdatedAt.Format(sql.TimestampFormat)
}

output.Edges = append(output.Edges, &node.EventEdge{
Expand Down Expand Up @@ -441,9 +441,9 @@ func (r *queryResolver) ContactList(ctx context.Context, filter *entity.Contact,
case "", "id":
cursor = n.ID
case "created_at":
cursor = n.CreatedAt.Format(sqlcipher.SQLiteTimestampFormats[0])
cursor = n.CreatedAt.Format(sql.TimestampFormat)
case "updated_at":
cursor = n.UpdatedAt.Format(sqlcipher.SQLiteTimestampFormats[0])
cursor = n.UpdatedAt.Format(sql.TimestampFormat)
}

output.Edges = append(output.Edges, &node.ContactEdge{
Expand Down Expand Up @@ -520,9 +520,9 @@ func (r *queryResolver) ConversationList(ctx context.Context, filter *entity.Con
case "", "id":
cursor = n.ID
case "created_at":
cursor = n.CreatedAt.Format(sqlcipher.SQLiteTimestampFormats[0])
cursor = n.CreatedAt.Format(sql.TimestampFormat)
case "updated_at":
cursor = n.UpdatedAt.Format(sqlcipher.SQLiteTimestampFormats[0])
cursor = n.UpdatedAt.Format(sql.TimestampFormat)
}

output.Edges = append(output.Edges, &node.ConversationEdge{
Expand Down
2 changes: 2 additions & 0 deletions core/sql/helpers.go
Expand Up @@ -7,6 +7,8 @@ import (
"github.com/jinzhu/gorm"
)

const TimestampFormat = "2006-01-02 15:04:05.999999999-07:00"

func ContactByID(db *gorm.DB, id string) (*entity.Contact, error) {
var contact entity.Contact
return &contact, db.First(&contact, "ID = ?", id).Error
Expand Down

0 comments on commit c3c19a8

Please sign in to comment.