set timezone for memo
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Steven Polley 2023-11-13 16:28:00 -07:00
parent f3a7df7de9
commit 77e467071b
2 changed files with 10 additions and 2 deletions

View File

@ -7,6 +7,7 @@ import (
"io" "io"
"net/http" "net/http"
"net/url" "net/url"
"os"
"time" "time"
) )
@ -22,6 +23,7 @@ type Client struct {
BudgetID string BudgetID string
httpClient *http.Client httpClient *http.Client
transport *http.Transport transport *http.Transport
loc *time.Location
} }
// Send an HTTP GET request, and return the processed response // Send an HTTP GET request, and return the processed response
@ -130,12 +132,18 @@ func NewClient(budgetID, bearerToken string) (*Client, error) {
Transport: transport, 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 // Create a new client
c := &Client{ c := &Client{
BudgetID: budgetID, BudgetID: budgetID,
BearerToken: bearerToken, BearerToken: bearerToken,
httpClient: client, httpClient: client,
transport: transport, transport: transport,
loc: loc,
} }
return c, nil return c, nil
} }

View File

@ -93,7 +93,7 @@ func (c *Client) createTodayYNABCapitalGainsTransaction(accountID string, amount
transaction.Transaction.Cleared = "cleared" transaction.Transaction.Cleared = "cleared"
transaction.Transaction.Approved = true transaction.Transaction.Approved = true
transaction.Transaction.PayeeName = "Capital Gains or Losses" 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{} response := &Transaction{}
@ -114,7 +114,7 @@ func (c *Client) updateTodayYNABCapitalGainsTransaction(accountID string, transa
transaction.Transaction.Cleared = "cleared" transaction.Transaction.Cleared = "cleared"
transaction.Transaction.Approved = true transaction.Transaction.Approved = true
transaction.Transaction.PayeeName = "Capital Gains or Losses" 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{} response := &Transaction{}