From 6d492069db2a025aebc41598672114779695cbf9 Mon Sep 17 00:00:00 2001 From: nyamanaka Date: Wed, 19 Jun 2024 09:59:26 +0900 Subject: [PATCH 1/3] due_date is unix timestamp --- v1/balance.go | 4 +++- v1/balance_test.go | 8 +++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/v1/balance.go b/v1/balance.go index 3141407..3cdf4e5 100644 --- a/v1/balance.go +++ b/v1/balance.go @@ -99,7 +99,8 @@ type BalanceResponse struct { Closed bool `json:"closed"` Statements []*StatementResponse RawStatements listResponseParser `json:"statements"` - DueDate string `json:"due_date"` + RawDueDate *int `json:"due_date"` + DueDate time.Time BankInfo *BankInfo `json:"bank_info"` Object string `json:"object"` @@ -112,6 +113,7 @@ func (t *BalanceResponse) UnmarshalJSON(b []byte) error { err := json.Unmarshal(b, &raw) if err == nil && raw.Object == "balance" { raw.CreatedAt = time.Unix(IntValue(raw.Created), 0) + raw.DueDate = time.Unix(IntValue(raw.RawDueDate), 0) raw.Statements = make([]*StatementResponse, len(raw.RawStatements.Data)) for i, r := range raw.RawStatements.Data { json.Unmarshal(r, &(raw.Statements[i])) diff --git a/v1/balance_test.go b/v1/balance_test.go index 24ab671..24fdf65 100644 --- a/v1/balance_test.go +++ b/v1/balance_test.go @@ -53,7 +53,8 @@ func TestParseBalance(t *testing.T) { assert.EqualValues(t, 1000, s.Net) assert.True(t, s.RawStatements.HasMore) assert.Equal(t, "st_xxx", s.Statements[0].ID) - assert.Equal(t, "", s.DueDate) + assert.Equal(t, (*int)(nil), s.RawDueDate) + assert.Equal(t, time.Unix(0, 0), s.DueDate) assert.Equal(t, "collecting", s.Type) assert.False(t, s.Closed) assert.Nil(t, s.BankInfo) @@ -66,10 +67,11 @@ func TestParseBalance(t *testing.T) { "bank_account_number": "1234567", "bank_account_holder_name": "ペイ タロウ", "bank_account_status": "pending" -}`, `"2015-09-16"`) +}`, `1711897200`) err = json.Unmarshal([]byte(balanceJSONStr2), s) assert.NoError(t, err) - assert.Equal(t, "2015-09-16", s.DueDate) + assert.Equal(t, 1711897200, *s.RawDueDate) + assert.Equal(t, time.Date(2024, 4, 1, 0, 0, 0, 0, time.Local), s.DueDate) assert.Equal(t, "0001", s.BankInfo.BankCode) assert.Equal(t, "123", s.BankInfo.BankBranchCode) assert.Equal(t, "普通", s.BankInfo.BankAccountType) From 7972333aa7a6b4631e56b92006896954132348a9 Mon Sep 17 00:00:00 2001 From: nyamanaka Date: Wed, 19 Jun 2024 10:13:33 +0900 Subject: [PATCH 2/3] version increment --- v1/client.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/v1/client.go b/v1/client.go index 993adae..c0a415b 100644 --- a/v1/client.go +++ b/v1/client.go @@ -15,7 +15,7 @@ import ( "time" ) -const Version = "v0.2.2" +const Version = "v0.2.3" const tagName = "form" const rateLimitStatusCode = 429 From ef9cacb81ffdd8fa024c44de9beb24ae7d5d2cc0 Mon Sep 17 00:00:00 2001 From: nyamanaka Date: Wed, 19 Jun 2024 10:17:51 +0900 Subject: [PATCH 3/3] compare with int value, not date --- v1/balance_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/v1/balance_test.go b/v1/balance_test.go index 24fdf65..52ca4c8 100644 --- a/v1/balance_test.go +++ b/v1/balance_test.go @@ -71,7 +71,7 @@ func TestParseBalance(t *testing.T) { err = json.Unmarshal([]byte(balanceJSONStr2), s) assert.NoError(t, err) assert.Equal(t, 1711897200, *s.RawDueDate) - assert.Equal(t, time.Date(2024, 4, 1, 0, 0, 0, 0, time.Local), s.DueDate) + assert.Equal(t, 1711897200, (int)(s.DueDate.Unix())) assert.Equal(t, "0001", s.BankInfo.BankCode) assert.Equal(t, "123", s.BankInfo.BankBranchCode) assert.Equal(t, "普通", s.BankInfo.BankAccountType)