From 77e467071b09864727ef4d6e976da321683b68bf Mon Sep 17 00:00:00 2001 From: Steven Polley Date: Mon, 13 Nov 2023 16:28:00 -0700 Subject: [PATCH] set timezone for memo --- ynab/client.go | 8 ++++++++ ynab/transactions.go | 4 ++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/ynab/client.go b/ynab/client.go index 88d3478..b4a845b 100644 --- a/ynab/client.go +++ b/ynab/client.go @@ -7,6 +7,7 @@ import ( "io" "net/http" "net/url" + "os" "time" ) @@ -22,6 +23,7 @@ type Client struct { BudgetID string httpClient *http.Client transport *http.Transport + loc *time.Location } // Send an HTTP GET request, and return the processed response @@ -130,12 +132,18 @@ func NewClient(budgetID, bearerToken string) (*Client, error) { Transport: transport, } + loc, err := time.LoadLocation(os.Getenv("TZ")) + if err != nil { + return nil, fmt.Errorf("failed to load timezone location '%s': %v", os.Getenv("TZ"), err) + } + // Create a new client c := &Client{ BudgetID: budgetID, BearerToken: bearerToken, httpClient: client, transport: transport, + loc: loc, } return c, nil } diff --git a/ynab/transactions.go b/ynab/transactions.go index 07222d4..9c5bfdd 100644 --- a/ynab/transactions.go +++ b/ynab/transactions.go @@ -93,7 +93,7 @@ func (c *Client) createTodayYNABCapitalGainsTransaction(accountID string, amount transaction.Transaction.Cleared = "cleared" transaction.Transaction.Approved = true transaction.Transaction.PayeeName = "Capital Gains or Losses" - transaction.Transaction.Memo = fmt.Sprintf("Quoted at: %s", time.Now().Format("2006-01-02 15:04:05")) + transaction.Transaction.Memo = fmt.Sprintf("Quoted at: %s", time.Now().In(c.loc).Format("2006-01-02 15:04:05")) response := &Transaction{} @@ -114,7 +114,7 @@ func (c *Client) updateTodayYNABCapitalGainsTransaction(accountID string, transa transaction.Transaction.Cleared = "cleared" transaction.Transaction.Approved = true transaction.Transaction.PayeeName = "Capital Gains or Losses" - transaction.Transaction.Memo = fmt.Sprintf("Quoted at: %s", time.Now().Format("2006-01-02 15:04:05")) + transaction.Transaction.Memo = fmt.Sprintf("Quoted at: %s", time.Now().In(c.loc).Format("2006-01-02 15:04:05")) response := &Transaction{}