Skip to content

Commit

Permalink
Fix timestamp changes
Browse files Browse the repository at this point in the history
  • Loading branch information
KrishnaDeqode committed Jun 17, 2020
1 parent 681e423 commit e126bd7
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 40 deletions.
35 changes: 17 additions & 18 deletions zboxcore/fileref/fileref.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"sort"
"strconv"
"strings"
"time"

"github.com/0chain/gosdk/core/encryption"
)
Expand Down Expand Up @@ -49,24 +48,24 @@ type RefEntity interface {
GetLookupHash() string
GetPath() string
GetName() string
GetCreatedAt() time.Time
GetUpdatedAt() time.Time
GetCreatedAt() string
GetUpdatedAt() string
}

type Ref struct {
Type string `json:"type"`
AllocationID string `json:"allocation_id"`
Name string `json:"name"`
Path string `json:"path"`
Size int64 `json:"size"`
Hash string `json:"hash"`
NumBlocks int64 `json:"num_of_blocks"`
PathHash string `json:"path_hash"`
LookupHash string `json:"lookup_hash"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
Type string `json:"type"`
AllocationID string `json:"allocation_id"`
Name string `json:"name"`
Path string `json:"path"`
Size int64 `json:"size"`
Hash string `json:"hash"`
NumBlocks int64 `json:"num_of_blocks"`
PathHash string `json:"path_hash"`
LookupHash string `json:"lookup_hash"`
childrenLoaded bool
Children []RefEntity `json:"-"`
CreatedAt string `json:"created_at"`
UpdatedAt string `json:"updated_at"`
}

func GetReferenceLookup(allocationID string, path string) string {
Expand Down Expand Up @@ -137,11 +136,11 @@ func (r *Ref) GetName() string {
return r.Name
}

func (r *Ref) GetCreatedAt() time.Time {
func (r *Ref) GetCreatedAt() string {
return r.CreatedAt
}

func (r *Ref) GetUpdatedAt() time.Time {
func (r *Ref) GetUpdatedAt() string {
return r.UpdatedAt
}

Expand Down Expand Up @@ -221,10 +220,10 @@ func (fr *FileRef) GetName() string {
return fr.Name
}

func (fr *FileRef) GetCreatedAt() time.Time {
func (fr *FileRef) GetCreatedAt() string {
return fr.CreatedAt
}

func (fr *FileRef) GetUpdatedAt() time.Time {
func (fr *FileRef) GetUpdatedAt() string {
return fr.UpdatedAt
}
20 changes: 0 additions & 20 deletions zboxcore/fileref/list.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package fileref

import (
"time"

"github.com/0chain/gosdk/core/common"
"github.com/mitchellh/mapstructure"
)
Expand All @@ -18,12 +16,6 @@ func (lr *ListResult) GetDirTree(allocationID string) (*Ref, error) {
if reftype == DIRECTORY {
rootRef := &Ref{Type: DIRECTORY}
rootRef.AllocationID = allocationID

rootRef.CreatedAt = parseTime(lr.Meta["created_at"].(string))
rootRef.UpdatedAt = parseTime(lr.Meta["updated_at"].(string))
delete(lr.Meta, "created_at")
delete(lr.Meta, "updated_at")

var md mapstructure.Metadata
config := &mapstructure.DecoderConfig{
Metadata: &md,
Expand Down Expand Up @@ -54,19 +46,13 @@ func (lr *ListResult) populateChildren(ref *Ref) error {
if reftype == DIRECTORY {
dref := &Ref{Type: DIRECTORY}
dref.AllocationID = ref.AllocationID
dref.CreatedAt = parseTime(rpc["created_at"].(string))
dref.UpdatedAt = parseTime(rpc["updated_at"].(string))
childEntity = dref
} else {
fref := &FileRef{}
fref.Type = FILE
fref.AllocationID = ref.AllocationID
fref.CreatedAt = parseTime(rpc["created_at"].(string))
fref.UpdatedAt = parseTime(rpc["updated_at"].(string))
childEntity = fref
}
delete(rpc, "created_at")
delete(rpc, "updated_at")
var md mapstructure.Metadata
config := &mapstructure.DecoderConfig{
Metadata: &md,
Expand All @@ -85,9 +71,3 @@ func (lr *ListResult) populateChildren(ref *Ref) error {
}
return nil
}

func parseTime(timeString string) time.Time {
layout := "2006-01-02T15:04:05.000000Z"
t, _ := time.Parse(layout, timeString)
return t
}
4 changes: 2 additions & 2 deletions zboxcore/sdk/listworker.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ type ListResult struct {
NumBlocks int64 `json:"num_blocks"`
LookupHash string `json:"lookup_hash"`
EncryptionKey string `json:"encryption_key"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
CreatedAt string `json:"created_at"`
UpdatedAt string `json:"updated_at"`
Children []*ListResult `json:"list"`
Consensus `json:"-"`
}
Expand Down

0 comments on commit e126bd7

Please sign in to comment.