From f0ac0a67b3e1e3e9b71131ffd1d2466b65875883 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?tiltwind=28=E6=96=9C=E9=A3=8E=29?= <116183822+tiltwind@users.noreply.github.com> Date: Fri, 24 Feb 2023 21:24:20 +0800 Subject: [PATCH] upgrade go to v1.17 to fix issue #348 (#352) --- .github/workflows/github-actions.yml | 2 +- date.go | 6 +++--- date_test.go | 16 ++++++++++++++++ 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/.github/workflows/github-actions.yml b/.github/workflows/github-actions.yml index 132f03e4..0e304f57 100644 --- a/.github/workflows/github-actions.yml +++ b/.github/workflows/github-actions.yml @@ -19,7 +19,7 @@ jobs: os: - ubuntu-latest go_version: - - 1.13 + - 1.17 jdk_version: - 1.8 env: diff --git a/date.go b/date.go index 0b5329aa..4fa6b259 100644 --- a/date.go +++ b/date.go @@ -42,12 +42,12 @@ func encDateInMs(b []byte, i interface{}) []byte { return append(b, BC_NULL) } b = append(b, BC_DATE) - return append(b, PackInt64(vi.UnixNano()/1e6)...) + return append(b, PackInt64(vi.UnixMilli())...) } -func encDateInMimute(b []byte, v time.Time) []byte { +func encDateInMinute(b []byte, v time.Time) []byte { b = append(b, BC_DATE_MINUTE) - return append(b, PackInt32(int32(v.UnixNano()/60e9))...) + return append(b, PackInt32(int32(v.Unix()/60))...) } ///////////////////////////////////////// diff --git a/date_test.go b/date_test.go index f0a8b6f3..2954ffc6 100644 --- a/date_test.go +++ b/date_test.go @@ -66,6 +66,22 @@ func TestEncDate(t *testing.T) { d = NewDecoder(e.Buffer()) res, err = d.Decode() t.Logf("decode(%s, %s) = %v, %v\n", v, tz.Local(), res, err) + assert.Equal(t, tz.Local(), res) +} + +func TestEncDateIssue348(t *testing.T) { + e := NewEncoder() + v := "2914-02-09 06:15:23" + tz, _ := time.Parse("2006-01-02 15:04:05", v) + e.Encode(tz) + if len(e.Buffer()) == 0 { + t.Fail() + } + + d := NewDecoder(e.Buffer()) + res, err := d.Decode() + t.Logf("decode(%s, %s) = %v, %v\n", v, tz.Local(), res, err) + assert.Equal(t, tz.Local(), res) } func testDateFramework(t *testing.T, method string, expected time.Time) {