diff --git a/pkg/base/adapter_go.go b/pkg/base/adapter_go.go new file mode 100644 index 0000000..476f93a --- /dev/null +++ b/pkg/base/adapter_go.go @@ -0,0 +1,19 @@ +// Copyright 2022, Chef. All rights reserved. +// https://github.com/q191201771/lal +// +// Use of this source code is governed by a MIT-style license +// that can be found in the License file. +// +// Author: Chef (191201771@qq.com) + +package base + +import "time" + +// 兼容老版本的Go,不直接使用新版本Go标准库中新增的内容 + +// TODO(chef): [refactor] 整理到naza中 202212 + +func UnixMilli(t time.Time) int64 { + return t.UnixNano() / 1e6 +} diff --git a/pkg/base/adapter_go_test.go b/pkg/base/adapter_go_test.go new file mode 100644 index 0000000..aa9c684 --- /dev/null +++ b/pkg/base/adapter_go_test.go @@ -0,0 +1,20 @@ +// Copyright 2022, Chef. All rights reserved. +// https://github.com/q191201771/lal +// +// Use of this source code is governed by a MIT-style license +// that can be found in the License file. +// +// Author: Chef (191201771@qq.com) + +package base + +import ( + "github.com/q191201771/naza/pkg/assert" + "testing" + "time" +) + +func TestUnixMilli(t *testing.T) { + n := time.Now() + assert.Equal(t, n.UnixMilli(), UnixMilli(n)) +} diff --git a/pkg/base/dump_file.go b/pkg/base/dump_file.go index 43579e5..7bbc207 100644 --- a/pkg/base/dump_file.go +++ b/pkg/base/dump_file.go @@ -150,7 +150,7 @@ func (d *DumpFile) pack(b []byte, typ uint32) []byte { i += 4 bele.BePutUint32(ret[i:], uint32(len(b))) // Len i += 4 - bele.BePutUint64(ret[i:], uint64(time.Now().UnixMilli())) // Timestamp + bele.BePutUint64(ret[i:], uint64(UnixMilli(time.Now()))) // Timestamp i += 8 copy(ret[i:], "LALD") i += 4