From 748ed71455465efe13be11872b4683113f4bc3df Mon Sep 17 00:00:00 2001 From: Gareth Kirwan Date: Tue, 18 Mar 2025 05:45:24 +0700 Subject: [PATCH] Huobi: Fix TestPairFromContractExpiryCode NW contract failure (#1809) Looks like "Within 2 weeks" fails on 22nd November during leap years. On 2025-02-21 we saw NW come up with 2025-03-07 for a few hours, and I'm guessing it's because they use local time. Added 1 day leeway to account for that timezone difference. --- exchanges/huobi/huobi_test.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/exchanges/huobi/huobi_test.go b/exchanges/huobi/huobi_test.go index 8bb32a2c..80e46381 100644 --- a/exchanges/huobi/huobi_test.go +++ b/exchanges/huobi/huobi_test.go @@ -1845,14 +1845,16 @@ func TestPairFromContractExpiryCode(t *testing.T) { require.True(t, ok, "%s type must be in contractExpiryNames", cType) assert.Equal(t, currency.BTC, p.Base, "pair Base should be the same") assert.Equal(t, exp, p.Quote, "pair Quote should be the same") - d, err := time.Parse("060102", p.Quote.String()) + tz, err := time.LoadLocation("Asia/Singapore") // Huobi HQ and apparent local time for when codes become effective + require.NoError(t, err, "LoadLocation must not error") + d, err := time.ParseInLocation("060102", p.Quote.String(), tz) require.NoError(t, err, "currency code must be a parsable date") require.Falsef(t, d.Before(n), "%s expiry must be today or after", cType) switch cType { case "CW", "NW": - require.True(t, d.Before(n.Add(24*time.Hour*14)), "%s expiry must be within 2 weeks", cType) + require.Truef(t, d.Before(n.AddDate(0, 0, 14)), "%s expiry must be within 14 days; Got: `%s`", cType, d) case "CQ", "NQ": - require.True(t, d.Before(n.Add(24*time.Hour*90*2)), "%s expiry must be within 2 quarters", cType) + require.Truef(t, d.Before(n.AddDate(0, 6, 0)), "%s expiry must be within 6 months; Got: `%s`", cType, d) } } }