From 5d8b5f9b2352aea48e235d46da497944b45ad966 Mon Sep 17 00:00:00 2001 From: Angga Bayu Marthafifsa Date: Tue, 1 Jan 2019 15:28:28 +0700 Subject: [PATCH] delete if time more than time now > 24 hour --- parser/devicePrsInternal.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/parser/devicePrsInternal.go b/parser/devicePrsInternal.go index 9eab194..2f87a92 100755 --- a/parser/devicePrsInternal.go +++ b/parser/devicePrsInternal.go @@ -9,6 +9,7 @@ import ( "encoding/binary" "fmt" "time" + "math" //"encoding/hex" "strconv" "sort" @@ -320,10 +321,18 @@ func parseData(data []byte, imei uint64, tagOption *opt.Options) (rec DeviceReco } deviceRecord.TagDevices = tags_ - deviceRecords = append(deviceRecords, deviceRecord) + + tstampToNow := time.Since(deviceRecord.Tstamp) + hCurr := math.Round(tstampToNow.Hours()*100)/100 + if hCurr >= -24 { + deviceRecords = append(deviceRecords, deviceRecord) + } + } + rec.NumRec = uint16(len(deviceRecords)) + //sort ascending by date sort.Sort(ByTstamp(deviceRecords))