1
0
mirror of https://github.com/aclindsa/ofxgo.git synced 2024-11-22 03:30:04 -05:00

Switch Date to contain time.Time instead of being a typedef

This commit is contained in:
Aaron Lindsay 2017-04-04 05:45:19 -04:00
parent 7f5ef5751d
commit 1560f44a3c
10 changed files with 151 additions and 167 deletions

View File

@ -68,7 +68,7 @@ func TestMarshalBankStatementRequest(t *testing.T) {
request.SetClientFields(&client)
// Overwrite the DtClient value set by SetClientFields to time.Now()
EST := time.FixedZone("EST", -5*60*60)
request.Signon.DtClient = ofxgo.Date(time.Date(2006, 1, 15, 11, 23, 0, 0, EST))
request.Signon.DtClient = *ofxgo.NewDate(2006, 1, 15, 11, 23, 0, 0, EST)
marshalCheckRequest(t, &request, expectedString)
}
@ -138,40 +138,36 @@ func TestUnmarshalBankStatementResponse(t *testing.T) {
</BANKMSGSRSV1>
</OFX>`)
var expected ofxgo.Response
GMT := time.FixedZone("GMT", 0)
expected.Version = "203"
expected.Signon.Status.Code = 0
expected.Signon.Status.Severity = "INFO"
expected.Signon.DtServer = ofxgo.Date(time.Date(2006, 1, 15, 11, 23, 03, 0, GMT))
expected.Signon.DtServer = *ofxgo.NewDateGMT(2006, 1, 15, 11, 23, 03, 0)
expected.Signon.Language = "ENG"
dtprofup := ofxgo.Date(time.Date(2005, 2, 21, 9, 13, 0, 0, GMT))
expected.Signon.DtProfUp = &dtprofup
dtacctup := ofxgo.Date(time.Date(2006, 1, 2, 16, 0, 0, 0, GMT))
expected.Signon.DtAcctUp = &dtacctup
expected.Signon.DtProfUp = ofxgo.NewDateGMT(2005, 2, 21, 9, 13, 0, 0)
expected.Signon.DtAcctUp = ofxgo.NewDateGMT(2006, 1, 2, 16, 0, 0, 0)
expected.Signon.Org = "BNK"
expected.Signon.Fid = "1987"
var trnamt1, trnamt2 ofxgo.Amount
trnamt1.SetFrac64(-20000, 100)
trnamt2.SetFrac64(-30000, 100)
dtuser2 := ofxgo.Date(time.Date(2006, 1, 12, 0, 0, 0, 0, GMT))
banktranlist := ofxgo.TransactionList{
DtStart: ofxgo.Date(time.Date(2006, 1, 1, 0, 0, 0, 0, GMT)),
DtEnd: ofxgo.Date(time.Date(2006, 1, 15, 0, 0, 0, 0, GMT)),
DtStart: *ofxgo.NewDateGMT(2006, 1, 1, 0, 0, 0, 0),
DtEnd: *ofxgo.NewDateGMT(2006, 1, 15, 0, 0, 0, 0),
Transactions: []ofxgo.Transaction{
{
TrnType: "CHECK",
DtPosted: ofxgo.Date(time.Date(2006, 1, 4, 0, 0, 0, 0, GMT)),
DtPosted: *ofxgo.NewDateGMT(2006, 1, 4, 0, 0, 0, 0),
TrnAmt: trnamt1,
FiTId: "00592",
CheckNum: "2002",
},
{
TrnType: "ATM",
DtPosted: ofxgo.Date(time.Date(2006, 1, 12, 0, 0, 0, 0, GMT)),
DtUser: &dtuser2,
DtPosted: *ofxgo.NewDateGMT(2006, 1, 12, 0, 0, 0, 0),
DtUser: ofxgo.NewDateGMT(2006, 1, 12, 0, 0, 0, 0),
TrnAmt: trnamt2,
FiTId: "00679",
},
@ -182,8 +178,6 @@ func TestUnmarshalBankStatementResponse(t *testing.T) {
balamt.SetFrac64(20029, 100)
availbalamt.SetFrac64(20029, 100)
availdtasof := ofxgo.Date(time.Date(2006, 1, 14, 16, 0, 0, 0, GMT))
statementResponse := ofxgo.StatementResponse{
TrnUID: "1001",
Status: ofxgo.Status{
@ -198,9 +192,9 @@ func TestUnmarshalBankStatementResponse(t *testing.T) {
},
BankTranList: &banktranlist,
BalAmt: balamt,
DtAsOf: ofxgo.Date(time.Date(2006, 1, 14, 16, 0, 0, 0, GMT)),
DtAsOf: *ofxgo.NewDateGMT(2006, 1, 14, 16, 0, 0, 0),
AvailBalAmt: &availbalamt,
AvailDtAsOf: &availdtasof,
AvailDtAsOf: ofxgo.NewDateGMT(2006, 1, 14, 16, 0, 0, 0),
}
expected.Bank = append(expected.Bank, &statementResponse)

View File

@ -144,7 +144,7 @@ func tryProfile(appId, appVer, version string, noindent bool) bool {
profileRequest := ofxgo.ProfileRequest{
TrnUID: *uid,
DtProfUp: ofxgo.Date(time.Unix(0, 0)),
DtProfUp: ofxgo.Date{Time: time.Unix(0, 0)},
}
query.Prof = append(query.Prof, &profileRequest)

View File

@ -31,7 +31,7 @@ func getAccounts() {
acctInfo := ofxgo.AcctInfoRequest{
TrnUID: *uid,
DtAcctUp: ofxgo.Date(time.Unix(0, 0)),
DtAcctUp: ofxgo.Date{Time: time.Unix(0, 0)},
}
query.Signup = append(query.Signup, &acctInfo)

View File

@ -53,21 +53,19 @@ func TestMarshalCCStatementRequest(t *testing.T) {
request.Signon.Org = "BNK"
request.Signon.Fid = "1987"
GMT := time.FixedZone("GMT", 0)
dtstart := ofxgo.Date(time.Date(2017, 1, 1, 0, 0, 0, 0, GMT))
statementRequest := ofxgo.CCStatementRequest{
TrnUID: "913846",
CCAcctFrom: ofxgo.CCAcct{
AcctId: "XXXXXXXXXXXX1234",
},
DtStart: &dtstart,
DtStart: ofxgo.NewDateGMT(2017, 1, 1, 0, 0, 0, 0),
Include: true,
}
request.CreditCard = append(request.CreditCard, &statementRequest)
request.SetClientFields(&client)
// Overwrite the DtClient value set by SetClientFields to time.Now()
request.Signon.DtClient = ofxgo.Date(time.Date(2017, 3, 31, 15, 38, 48, 0, GMT))
request.Signon.DtClient = *ofxgo.NewDateGMT(2017, 3, 31, 15, 38, 48, 0)
marshalCheckRequest(t, &request, expectedString)
}
@ -85,7 +83,6 @@ NEWFILEUID:NONE
<OFX><SIGNONMSGSRSV1><SONRS><STATUS><CODE>0<SEVERITY>INFO<MESSAGE>SUCCESS</STATUS><DTSERVER>20170331154648.331[-4:EDT]<LANGUAGE>ENG<FI><ORG>01<FID>81729</FI></SONRS></SIGNONMSGSRSV1><CREDITCARDMSGSRSV1><CCSTMTTRNRS><TRNUID>59e850ad-7448-b4ce-4b71-29057763b306<STATUS><CODE>0<SEVERITY>INFO</STATUS><CCSTMTRS><CURDEF>USD<CCACCTFROM><ACCTID>9283744488463775</CCACCTFROM><BANKTRANLIST><DTSTART>20161201154648.688[-5:EST]<DTEND>20170331154648.688[-4:EDT]<STMTTRN><TRNTYPE>DEBIT<DTPOSTED>20170209120000[0:GMT]<TRNAMT>-7.96<FITID>2017020924435657040207171600195<NAME>SLICE OF NY</STMTTRN><STMTTRN><TRNTYPE>CREDIT<DTPOSTED>20161228120000[0:GMT]<TRNAMT>3830.46<FITID>2016122823633637200000258482730<NAME>Payment Thank You Electro</STMTTRN><STMTTRN><TRNTYPE>DEBIT<DTPOSTED>20170327120000[0:GMT]<TRNAMT>-17.7<FITID>2017032724445727085300442885680<NAME>KROGER FUEL #9999</STMTTRN></BANKTRANLIST><LEDGERBAL><BALAMT>-9334<DTASOF>20170331080000.000[-4:EDT]</LEDGERBAL><AVAILBAL><BALAMT>7630.17<DTASOF>20170331080000.000[-4:EDT]</AVAILBAL></CCSTMTRS></CCSTMTTRNRS></CREDITCARDMSGSRSV1></OFX>`)
var expected ofxgo.Response
GMT := time.FixedZone("GMT", 0)
EDT := time.FixedZone("EDT", -4*60*60)
EST := time.FixedZone("EST", -5*60*60)
@ -93,7 +90,7 @@ NEWFILEUID:NONE
expected.Signon.Status.Code = 0
expected.Signon.Status.Severity = "INFO"
expected.Signon.Status.Message = "SUCCESS"
expected.Signon.DtServer = ofxgo.Date(time.Date(2017, 3, 31, 15, 46, 48, 331000000, EDT))
expected.Signon.DtServer = *ofxgo.NewDate(2017, 3, 31, 15, 46, 48, 331000000, EDT)
expected.Signon.Language = "ENG"
expected.Signon.Org = "01"
expected.Signon.Fid = "81729"
@ -104,26 +101,26 @@ NEWFILEUID:NONE
trnamt3.SetFrac64(-1770, 100)
banktranlist := ofxgo.TransactionList{
DtStart: ofxgo.Date(time.Date(2016, 12, 1, 15, 46, 48, 688000000, EST)),
DtEnd: ofxgo.Date(time.Date(2017, 3, 31, 15, 46, 48, 688000000, EDT)),
DtStart: *ofxgo.NewDate(2016, 12, 1, 15, 46, 48, 688000000, EST),
DtEnd: *ofxgo.NewDate(2017, 3, 31, 15, 46, 48, 688000000, EDT),
Transactions: []ofxgo.Transaction{
{
TrnType: "DEBIT",
DtPosted: ofxgo.Date(time.Date(2017, 2, 9, 12, 0, 0, 0, GMT)),
DtPosted: *ofxgo.NewDateGMT(2017, 2, 9, 12, 0, 0, 0),
TrnAmt: trnamt1,
FiTId: "2017020924435657040207171600195",
Name: "SLICE OF NY",
},
{
TrnType: "CREDIT",
DtPosted: ofxgo.Date(time.Date(2016, 12, 28, 12, 0, 0, 0, GMT)),
DtPosted: *ofxgo.NewDateGMT(2016, 12, 28, 12, 0, 0, 0),
TrnAmt: trnamt2,
FiTId: "2016122823633637200000258482730",
Name: "Payment Thank You Electro",
},
{
TrnType: "DEBIT",
DtPosted: ofxgo.Date(time.Date(2017, 3, 27, 12, 0, 0, 0, GMT)),
DtPosted: *ofxgo.NewDateGMT(2017, 3, 27, 12, 0, 0, 0),
TrnAmt: trnamt3,
FiTId: "2017032724445727085300442885680",
Name: "KROGER FUEL #9999",
@ -135,8 +132,6 @@ NEWFILEUID:NONE
balamt.SetFrac64(-933400, 100)
availbalamt.SetFrac64(763017, 100)
availdtasof := ofxgo.Date(time.Date(2017, 3, 31, 8, 0, 0, 0, EDT))
statementResponse := ofxgo.CCStatementResponse{
TrnUID: "59e850ad-7448-b4ce-4b71-29057763b306",
Status: ofxgo.Status{
@ -149,9 +144,9 @@ NEWFILEUID:NONE
},
BankTranList: &banktranlist,
BalAmt: balamt,
DtAsOf: ofxgo.Date(time.Date(2017, 3, 31, 8, 0, 0, 0, EDT)),
DtAsOf: *ofxgo.NewDate(2017, 3, 31, 8, 0, 0, 0, EDT),
AvailBalAmt: &availbalamt,
AvailDtAsOf: &availdtasof,
AvailDtAsOf: ofxgo.NewDate(2017, 3, 31, 8, 0, 0, 0, EDT),
}
expected.CreditCard = append(expected.CreditCard, &statementResponse)

View File

@ -60,7 +60,6 @@ func TestMarshalInvStatementRequest(t *testing.T) {
request.Signon.Fid = "01"
EST := time.FixedZone("EST", -5*60*60)
dtstart := ofxgo.Date(time.Date(2016, 1, 1, 0, 0, 0, 0, EST))
statementRequest := ofxgo.InvStatementRequest{
TrnUID: "382827d6-e2d0-4396-bf3b-665979285420",
@ -68,7 +67,7 @@ func TestMarshalInvStatementRequest(t *testing.T) {
BrokerId: "fi.example.com",
AcctId: "82736664",
},
DtStart: &dtstart,
DtStart: ofxgo.NewDate(2016, 1, 1, 0, 0, 0, 0, EST),
Include: true,
IncludeOO: true,
IncludePos: true,
@ -78,7 +77,7 @@ func TestMarshalInvStatementRequest(t *testing.T) {
request.SetClientFields(&client)
// Overwrite the DtClient value set by SetClientFields to time.Now()
request.Signon.DtClient = ofxgo.Date(time.Date(2016, 2, 24, 13, 19, 5, 0, EST))
request.Signon.DtClient = *ofxgo.NewDate(2016, 2, 24, 13, 19, 5, 0, EST)
marshalCheckRequest(t, &request, expectedString)
}
@ -297,12 +296,11 @@ func TestUnmarshalInvStatementResponse(t *testing.T) {
</SECLISTMSGSRSV1>
</OFX>`)
var expected ofxgo.Response
GMT := time.FixedZone("GMT", 0)
expected.Version = "203"
expected.Signon.Status.Code = 0
expected.Signon.Status.Severity = "INFO"
expected.Signon.DtServer = ofxgo.Date(time.Date(2017, 4, 1, 20, 12, 44, 0, GMT))
expected.Signon.DtServer = *ofxgo.NewDateGMT(2017, 4, 1, 20, 12, 44, 0)
expected.Signon.Language = "ENG"
expected.Signon.Org = "INVSTRUS"
expected.Signon.Fid = "9999"
@ -314,20 +312,16 @@ func TestUnmarshalInvStatementResponse(t *testing.T) {
total1.SetFrac64(-22909, 1)
amount2.SetFrac64(22000, 1)
dtuser := ofxgo.Date(time.Date(2017, 1, 18, 0, 0, 0, 0, GMT))
dtavail := ofxgo.Date(time.Date(2017, 1, 23, 0, 0, 0, 0, GMT))
dtsettle := ofxgo.Date(time.Date(2017, 2, 7, 0, 0, 0, 0, GMT))
invtranlist := ofxgo.InvTranList{
DtStart: ofxgo.Date(time.Date(2017, 1, 1, 0, 0, 0, 0, GMT)),
DtEnd: ofxgo.Date(time.Date(2017, 3, 31, 0, 0, 0, 0, GMT)),
DtStart: *ofxgo.NewDateGMT(2017, 1, 1, 0, 0, 0, 0),
DtEnd: *ofxgo.NewDateGMT(2017, 3, 31, 0, 0, 0, 0),
InvTransactions: []ofxgo.InvTransaction{
ofxgo.BuyStock{
InvBuy: ofxgo.InvBuy{
InvTran: ofxgo.InvTran{
FiTId: "729483191",
DtTrade: ofxgo.Date(time.Date(2017, 2, 3, 0, 0, 0, 0, GMT)),
DtSettle: &dtsettle,
DtTrade: *ofxgo.NewDateGMT(2017, 2, 3, 0, 0, 0, 0),
DtSettle: ofxgo.NewDateGMT(2017, 2, 7, 0, 0, 0, 0),
},
SecId: ofxgo.SecurityId{
UniqueId: "78462F103",
@ -348,13 +342,14 @@ func TestUnmarshalInvStatementResponse(t *testing.T) {
Transactions: []ofxgo.Transaction{
ofxgo.Transaction{
TrnType: "CREDIT",
DtPosted: ofxgo.Date(time.Date(2017, 1, 20, 0, 0, 0, 0, GMT)),
DtUser: &dtuser,
DtAvail: &dtavail,
TrnAmt: amount2,
FiTId: "993838",
Name: "DEPOSIT",
Memo: "CHECK 19980",
DtPosted: *ofxgo.NewDateGMT(2017, 1, 20, 0, 0, 0, 0),
DtUser: ofxgo.NewDateGMT(2017, 1, 18, 0, 0, 0, 0),
DtAvail: ofxgo.NewDateGMT(2017, 1, 23, 0, 0, 0, 0),
TrnAmt: amount2,
FiTId: "993838",
Name: "DEPOSIT",
Memo: "CHECK 19980",
},
},
SubAcctFund: "CASH",
@ -368,8 +363,6 @@ func TestUnmarshalInvStatementResponse(t *testing.T) {
shortbalance.SetFrac64(0, 1)
balvalue.SetFrac64(25, 100)
baldtasof := ofxgo.Date(time.Date(2017, 4, 1, 0, 0, 0, 0, GMT))
invbalance := ofxgo.InvBalance{
AvailCash: availcash,
MarginBalance: marginbalance,
@ -380,7 +373,7 @@ func TestUnmarshalInvStatementResponse(t *testing.T) {
Desc: "Current interest rate for sweep account balances",
BalType: "PERCENT",
Value: balvalue,
DtAsOf: &baldtasof,
DtAsOf: ofxgo.NewDateGMT(2017, 4, 1, 0, 0, 0, 0),
},
},
}
@ -405,7 +398,7 @@ func TestUnmarshalInvStatementResponse(t *testing.T) {
Code: 0,
Severity: "INFO",
},
DtAsOf: ofxgo.Date(time.Date(2017, 3, 31, 0, 0, 0, 0, GMT)),
DtAsOf: *ofxgo.NewDateGMT(2017, 3, 31, 0, 0, 0, 0),
CurDef: "USD",
InvAcctFrom: ofxgo.InvAcct{
BrokerId: "invstrus.com",
@ -424,7 +417,7 @@ func TestUnmarshalInvStatementResponse(t *testing.T) {
Units: posunits1,
UnitPrice: posunitprice1,
MktVal: posmktval1,
DtPriceAsOf: ofxgo.Date(time.Date(2017, 3, 31, 16, 0, 0, 0, GMT)),
DtPriceAsOf: *ofxgo.NewDateGMT(2017, 3, 31, 16, 0, 0, 0),
Memo: "Price as of previous close",
},
},
@ -439,7 +432,7 @@ func TestUnmarshalInvStatementResponse(t *testing.T) {
Units: posunits2,
UnitPrice: posunitprice2,
MktVal: posmktval2,
DtPriceAsOf: ofxgo.Date(time.Date(2017, 3, 31, 16, 0, 0, 0, GMT)),
DtPriceAsOf: *ofxgo.NewDateGMT(2017, 3, 31, 16, 0, 0, 0),
},
},
},
@ -452,7 +445,7 @@ func TestUnmarshalInvStatementResponse(t *testing.T) {
UniqueId: "922908645",
UniqueIdType: "CUSIP",
},
DtPlaced: ofxgo.Date(time.Date(2017, 3, 10, 12, 44, 45, 0, GMT)),
DtPlaced: *ofxgo.NewDateGMT(2017, 3, 10, 12, 44, 45, 0),
Units: oounits1,
SubAcct: "CASH",
Duration: "GOODTILCANCEL",
@ -469,7 +462,7 @@ func TestUnmarshalInvStatementResponse(t *testing.T) {
UniqueId: "899422348",
UniqueIdType: "CUSIP",
},
DtPlaced: ofxgo.Date(time.Date(2017, 3, 24, 3, 19, 0, 0, GMT)),
DtPlaced: *ofxgo.NewDateGMT(2017, 3, 24, 3, 19, 0, 0),
Units: oounits2,
SubAcct: "CASH",
Duration: "GOODTILCANCEL",
@ -514,7 +507,7 @@ func TestUnmarshalInvStatementResponse(t *testing.T) {
},
OptType: "PUT",
StrikePrice: strikeprice,
DtExpire: ofxgo.Date(time.Date(2017, 9, 1, 0, 0, 0, 0, GMT)),
DtExpire: *ofxgo.NewDateGMT(2017, 9, 1, 0, 0, 0, 0),
ShPerCtrct: 100,
SecId: &ofxgo.SecurityId{
UniqueId: "983322180",
@ -722,12 +715,11 @@ NEWFILEUID: NONE
</SECLISTMSGSRSV1>
</OFX>`)
var expected ofxgo.Response
GMT := time.FixedZone("GMT", 0)
expected.Version = "102"
expected.Signon.Status.Code = 0
expected.Signon.Status.Severity = "INFO"
expected.Signon.DtServer = ofxgo.Date(time.Date(2017, 4, 3, 12, 0, 0, 0, GMT))
expected.Signon.DtServer = *ofxgo.NewDateGMT(2017, 4, 3, 12, 0, 0, 0)
expected.Signon.Language = "ENG"
expected.Signon.Org = "VV"
expected.Signon.Fid = "1000"
@ -742,20 +734,16 @@ NEWFILEUID: NONE
units2.SetFrac64(-100, 1)
units3.SetFrac64(1, 1)
dtsettle1 := ofxgo.Date(time.Date(2016, 12, 8, 12, 0, 0, 0, GMT))
dtsettle2 := ofxgo.Date(time.Date(2016, 12, 20, 12, 0, 0, 0, GMT))
dtsettle3 := ofxgo.Date(time.Date(2016, 12, 15, 12, 0, 0, 0, GMT))
invtranlist := ofxgo.InvTranList{
DtStart: ofxgo.Date(time.Date(2016, 12, 6, 12, 0, 0, 0, GMT)),
DtEnd: ofxgo.Date(time.Date(2017, 4, 3, 12, 0, 0, 0, GMT)),
DtStart: *ofxgo.NewDateGMT(2016, 12, 6, 12, 0, 0, 0),
DtEnd: *ofxgo.NewDateGMT(2017, 4, 3, 12, 0, 0, 0),
InvTransactions: []ofxgo.InvTransaction{
ofxgo.SellOpt{
InvSell: ofxgo.InvSell{
InvTran: ofxgo.InvTran{
FiTId: "12341234-20161207-1",
DtTrade: ofxgo.Date(time.Date(2016, 12, 7, 12, 0, 0, 0, GMT)),
DtSettle: &dtsettle1,
DtTrade: *ofxgo.NewDateGMT(2016, 12, 7, 12, 0, 0, 0),
DtSettle: ofxgo.NewDateGMT(2016, 12, 8, 12, 0, 0, 0),
},
SecId: ofxgo.SecurityId{
UniqueId: "SPY161216C00226000",
@ -775,8 +763,8 @@ NEWFILEUID: NONE
ofxgo.ClosureOpt{
InvTran: ofxgo.InvTran{
FiTId: "12341234-20161215-1",
DtTrade: ofxgo.Date(time.Date(2016, 12, 15, 12, 0, 0, 0, GMT)),
DtSettle: &dtsettle2,
DtTrade: *ofxgo.NewDateGMT(2016, 12, 15, 12, 0, 0, 0),
DtSettle: ofxgo.NewDateGMT(2016, 12, 20, 12, 0, 0, 0),
},
SecId: ofxgo.SecurityId{
UniqueId: "78462F10",
@ -790,8 +778,8 @@ NEWFILEUID: NONE
ofxgo.ClosureOpt{
InvTran: ofxgo.InvTran{
FiTId: "12341234-20161215-2",
DtTrade: ofxgo.Date(time.Date(2016, 12, 15, 12, 0, 0, 0, GMT)),
DtSettle: &dtsettle3,
DtTrade: *ofxgo.NewDateGMT(2016, 12, 15, 12, 0, 0, 0),
DtSettle: ofxgo.NewDateGMT(2016, 12, 15, 12, 0, 0, 0),
},
SecId: ofxgo.SecurityId{
UniqueId: "SPY161216C00226000",
@ -830,7 +818,7 @@ NEWFILEUID: NONE
Code: 0,
Severity: "INFO",
},
DtAsOf: ofxgo.Date(time.Date(2017, 4, 3, 12, 0, 0, 0, GMT)),
DtAsOf: *ofxgo.NewDateGMT(2017, 4, 3, 12, 0, 0, 0),
CurDef: "USD",
InvAcctFrom: ofxgo.InvAcct{
BrokerId: "www.exampletrader.com",
@ -849,7 +837,7 @@ NEWFILEUID: NONE
Units: posunits1,
UnitPrice: posunitprice1,
MktVal: posmktval1,
DtPriceAsOf: ofxgo.Date(time.Date(2017, 4, 3, 12, 0, 0, 0, GMT)),
DtPriceAsOf: *ofxgo.NewDateGMT(2017, 4, 3, 12, 0, 0, 0),
},
},
ofxgo.StockPosition{
@ -863,7 +851,7 @@ NEWFILEUID: NONE
Units: posunits2,
UnitPrice: posunitprice2,
MktVal: posmktval2,
DtPriceAsOf: ofxgo.Date(time.Date(2017, 4, 3, 12, 0, 0, 0, GMT)),
DtPriceAsOf: *ofxgo.NewDateGMT(2017, 4, 3, 12, 0, 0, 0),
},
},
},
@ -897,7 +885,7 @@ NEWFILEUID: NONE
},
OptType: "CALL",
StrikePrice: strikeprice,
DtExpire: ofxgo.Date(time.Date(2016, 12, 16, 12, 0, 0, 0, GMT)),
DtExpire: *ofxgo.NewDateGMT(2016, 12, 16, 12, 0, 0, 0),
ShPerCtrct: 100,
},
},

View File

@ -52,13 +52,13 @@ func TestMarshalProfileRequest(t *testing.T) {
profileRequest := ofxgo.ProfileRequest{
TrnUID: "983373",
DtProfUp: ofxgo.Date(time.Date(2016, 1, 1, 0, 0, 0, 0, EST)),
DtProfUp: *ofxgo.NewDate(2016, 1, 1, 0, 0, 0, 0, EST),
}
request.Prof = append(request.Prof, &profileRequest)
request.SetClientFields(&client)
// Overwrite the DtClient value set by SetClientFields to time.Now()
request.Signon.DtClient = ofxgo.Date(time.Date(2016, 6, 14, 7, 34, 0, 0, EST))
request.Signon.DtClient = *ofxgo.NewDate(2016, 6, 14, 7, 34, 0, 0, EST)
marshalCheckRequest(t, &request, expectedString)
}
@ -214,15 +214,13 @@ NEWFILEUID:NONE
</PROFMSGSRSV1>
</OFX>`)
var expected ofxgo.Response
GMT := time.FixedZone("GMT", 0)
expected.Version = "102"
expected.Signon.Status.Code = 0
expected.Signon.Status.Severity = "INFO"
expected.Signon.DtServer = ofxgo.Date(time.Date(2017, 4, 3, 9, 34, 58, 0, GMT))
expected.Signon.DtServer = *ofxgo.NewDateGMT(2017, 4, 3, 9, 34, 58, 0)
expected.Signon.Language = "ENG"
dtprofup := ofxgo.Date(time.Date(2002, 11, 19, 14, 0, 0, 0, GMT))
expected.Signon.DtProfUp = &dtprofup
expected.Signon.DtProfUp = ofxgo.NewDateGMT(2002, 11, 19, 14, 0, 0, 0)
profileResponse := ofxgo.ProfileResponse{
TrnUID: "0f94ce83-13b7-7568-e4fc-c02c7b47e7ab",
@ -305,7 +303,7 @@ NEWFILEUID:NONE
ChgPinFirst: false,
},
},
DtProfUp: ofxgo.Date(time.Date(2002, 11, 19, 14, 0, 0, 0, GMT)),
DtProfUp: *ofxgo.NewDateGMT(2002, 11, 19, 14, 0, 0, 0),
FiName: "Example Trade Financial",
Addr1: "5555 Buhunkus Drive",
City: "Someville",

View File

@ -62,7 +62,7 @@ func marshalMessageSet(e *xml.Encoder, requests []Message, set messageType) erro
// Overwrite the fields in this Request object controlled by the Client
func (oq *Request) SetClientFields(c *Client) {
oq.Signon.DtClient = Date(time.Now())
oq.Signon.DtClient.Time = time.Now()
// Overwrite fields that the client controls
oq.Version = c.OfxVersion()

View File

@ -51,13 +51,13 @@ func TestMarshalAcctInfoRequest(t *testing.T) {
acctInfoRequest := ofxgo.AcctInfoRequest{
TrnUID: "e3ad9bda-38fa-4e5b-8099-1bd567ddef7a",
DtAcctUp: ofxgo.Date(time.Date(2015, 12, 21, 18, 29, 45, 0, EST)),
DtAcctUp: *ofxgo.NewDate(2015, 12, 21, 18, 29, 45, 0, EST),
}
request.Signup = append(request.Signup, &acctInfoRequest)
request.SetClientFields(&client)
// Overwrite the DtClient value set by SetClientFields to time.Now()
request.Signon.DtClient = ofxgo.Date(time.Date(2016, 1, 15, 11, 23, 0, 0, EST))
request.Signon.DtClient = *ofxgo.NewDate(2016, 1, 15, 11, 23, 0, 0, EST)
marshalCheckRequest(t, &request, expectedString)
}
@ -111,17 +111,14 @@ func TestUnmarshalAcctInfoResponse(t *testing.T) {
</SIGNUPMSGSRSV1>
</OFX>`)
var expected ofxgo.Response
GMT := time.FixedZone("GMT", 0)
expected.Version = "203"
expected.Signon.Status.Code = 0
expected.Signon.Status.Severity = "INFO"
expected.Signon.DtServer = ofxgo.Date(time.Date(2006, 1, 15, 11, 23, 03, 0, GMT))
expected.Signon.DtServer = *ofxgo.NewDateGMT(2006, 1, 15, 11, 23, 03, 0)
expected.Signon.Language = "ENG"
dtprofup := ofxgo.Date(time.Date(2005, 2, 21, 9, 13, 0, 0, GMT))
expected.Signon.DtProfUp = &dtprofup
dtacctup := ofxgo.Date(time.Date(2006, 1, 2, 16, 0, 0, 0, GMT))
expected.Signon.DtAcctUp = &dtacctup
expected.Signon.DtProfUp = ofxgo.NewDateGMT(2005, 2, 21, 9, 13, 0, 0)
expected.Signon.DtAcctUp = ofxgo.NewDateGMT(2006, 1, 2, 16, 0, 0, 0)
expected.Signon.Org = "BNK"
expected.Signon.Fid = "1987"
@ -143,7 +140,7 @@ func TestUnmarshalAcctInfoResponse(t *testing.T) {
Code: 0,
Severity: "INFO",
},
DtAcctUp: ofxgo.Date(time.Date(2005, 2, 28, 0, 0, 0, 0, GMT)),
DtAcctUp: *ofxgo.NewDateGMT(2005, 2, 28, 0, 0, 0, 0),
AcctInfo: []ofxgo.AcctInfo{{
Desc: "Personal Checking",
Phone: "888-222-5827",

View File

@ -73,7 +73,9 @@ func (a Amount) Equal(o Amount) bool {
return (&a).Cmp(&o.Rat) == 0
}
type Date time.Time
type Date struct {
time.Time
}
var ofxDateFormats = []string{
"20060102150405.000",
@ -139,8 +141,7 @@ func (od *Date) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
for _, format := range ofxDateFormats {
t, err := time.Parse(format+zoneFormat, value+zone)
if err == nil {
tmpod := Date(t)
*od = tmpod
od.Time = t
return nil
}
}
@ -148,9 +149,8 @@ func (od *Date) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
}
func (od Date) String() string {
t := time.Time(od)
format := t.Format(ofxDateFormats[0])
zonename, zoneoffset := t.Zone()
format := od.Format(ofxDateFormats[0])
zonename, zoneoffset := od.Zone()
if zoneoffset < 0 {
format += "[" + fmt.Sprintf("%+d", zoneoffset/3600)
} else {
@ -175,7 +175,17 @@ func (od *Date) MarshalXML(e *xml.Encoder, start xml.StartElement) error {
}
func (od Date) Equal(o Date) bool {
return time.Time(od).Equal(time.Time(o))
return od.Time.Equal(o.Time)
}
func NewDate(year int, month time.Month, day, hour, min, sec, nsec int, loc *time.Location) *Date {
return &Date{Time: time.Date(year, month, day, hour, min, sec, nsec, loc)}
}
var gmt = time.FixedZone("GMT", 0)
func NewDateGMT(year int, month time.Month, day, hour, min, sec, nsec int) *Date {
return &Date{Time: time.Date(year, month, day, hour, min, sec, nsec, gmt)}
}
type String string

View File

@ -122,7 +122,7 @@ func TestUnmarshalAmount(t *testing.T) {
}
func TestMarshalDate(t *testing.T) {
var d ofxgo.Date
var d *ofxgo.Date
UTC := time.FixedZone("UTC", 0)
GMT_nodesc := time.FixedZone("", 0)
EST := time.FixedZone("EST", -5*60*60)
@ -130,32 +130,35 @@ func TestMarshalDate(t *testing.T) {
IST := time.FixedZone("IST", (5*60+30)*60)
NST := time.FixedZone("NST", -(3*60+30)*60)
d = ofxgo.Date(time.Date(2017, 3, 14, 15, 9, 26, 53*1000*1000, NPT))
marshalHelper(t, "20170314150926.053[5.75:NPT]", &d)
d = ofxgo.Date(time.Date(2017, 3, 14, 15, 9, 26, 53*1000*1000, EST))
marshalHelper(t, "20170314150926.053[-5:EST]", &d)
d = ofxgo.Date(time.Date(2017, 3, 14, 15, 9, 26, 53*1000*1000, UTC))
marshalHelper(t, "20170314150926.053[0:UTC]", &d)
d = ofxgo.Date(time.Date(2017, 3, 14, 15, 9, 26, 53*1000*1000, IST))
marshalHelper(t, "20170314150926.053[5.50:IST]", &d)
d = ofxgo.Date(time.Date(9999, 11, 1, 23, 59, 59, 1000, EST))
marshalHelper(t, "99991101235959.000[-5:EST]", &d)
d = ofxgo.Date(time.Date(0, 1, 1, 0, 0, 0, 0, IST))
marshalHelper(t, "00000101000000.000[5.50:IST]", &d)
d = ofxgo.Date(time.Unix(0, 0).In(UTC))
marshalHelper(t, "19700101000000.000[0:UTC]", &d)
d = ofxgo.Date(time.Date(2017, 3, 14, 0, 0, 26, 53*1000*1000, EST))
marshalHelper(t, "20170314000026.053[-5:EST]", &d)
d = ofxgo.Date(time.Date(2017, 3, 14, 0, 0, 26, 53*1000*1000, NST))
marshalHelper(t, "20170314000026.053[-3.50:NST]", &d)
d = ofxgo.NewDateGMT(2017, 3, 14, 15, 9, 26, 53*1000*1000)
marshalHelper(t, "20170314150926.053[0:GMT]", d)
d = ofxgo.NewDate(2017, 3, 14, 15, 9, 26, 53*1000*1000, NPT)
marshalHelper(t, "20170314150926.053[5.75:NPT]", d)
d = ofxgo.NewDate(2017, 3, 14, 15, 9, 26, 53*1000*1000, EST)
marshalHelper(t, "20170314150926.053[-5:EST]", d)
d = ofxgo.NewDate(2017, 3, 14, 15, 9, 26, 53*1000*1000, UTC)
marshalHelper(t, "20170314150926.053[0:UTC]", d)
d = ofxgo.NewDate(2017, 3, 14, 15, 9, 26, 53*1000*1000, IST)
marshalHelper(t, "20170314150926.053[5.50:IST]", d)
d = ofxgo.NewDate(9999, 11, 1, 23, 59, 59, 1000, EST)
marshalHelper(t, "99991101235959.000[-5:EST]", d)
d = ofxgo.NewDate(0, 1, 1, 0, 0, 0, 0, IST)
marshalHelper(t, "00000101000000.000[5.50:IST]", d)
d = &ofxgo.Date{Time: time.Unix(0, 0).In(UTC)}
marshalHelper(t, "19700101000000.000[0:UTC]", d)
d = ofxgo.NewDate(2017, 3, 14, 0, 0, 26, 53*1000*1000, EST)
marshalHelper(t, "20170314000026.053[-5:EST]", d)
d = ofxgo.NewDate(2017, 3, 14, 0, 0, 26, 53*1000*1000, NST)
marshalHelper(t, "20170314000026.053[-3.50:NST]", d)
// Time zone without textual description
d = ofxgo.Date(time.Date(2017, 3, 14, 15, 9, 26, 53*1000*1000, GMT_nodesc))
marshalHelper(t, "20170314150926.053[0]", &d)
d = ofxgo.NewDate(2017, 3, 14, 15, 9, 26, 53*1000*1000, GMT_nodesc)
marshalHelper(t, "20170314150926.053[0]", d)
}
func TestUnmarshalDate(t *testing.T) {
var d, overwritten ofxgo.Date
var d *ofxgo.Date
var overwritten ofxgo.Date
GMT := time.FixedZone("GMT", 0)
EST := time.FixedZone("EST", -5*60*60)
NPT := time.FixedZone("NPT", (5*60+45)*60)
@ -166,62 +169,61 @@ func TestUnmarshalDate(t *testing.T) {
eq := func(a, b interface{}) bool {
if dateA, ok := a.(*ofxgo.Date); ok {
if dateB, ok2 := b.(*ofxgo.Date); ok2 {
timeA := (*time.Time)(dateA)
return timeA.Equal((time.Time)(*dateB))
return dateA.Equal(*dateB)
}
}
return false
}
// Ensure omitted fields default to the correct values
d = ofxgo.Date(time.Date(2017, 3, 14, 15, 9, 26, 53*1000*1000, GMT))
unmarshalHelper2(t, "20170314150926.053[0]", &d, &overwritten, eq)
unmarshalHelper2(t, "20170314150926.053", &d, &overwritten, eq)
d = ofxgo.Date(time.Date(2017, 3, 14, 0, 0, 0, 0, GMT))
unmarshalHelper2(t, "20170314", &d, &overwritten, eq)
d = ofxgo.NewDateGMT(2017, 3, 14, 15, 9, 26, 53*1000*1000)
unmarshalHelper2(t, "20170314150926.053[0]", d, &overwritten, eq)
unmarshalHelper2(t, "20170314150926.053", d, &overwritten, eq)
d = ofxgo.NewDate(2017, 3, 14, 0, 0, 0, 0, GMT)
unmarshalHelper2(t, "20170314", d, &overwritten, eq)
// Ensure all signs on time zone offsets are properly handled
d = ofxgo.Date(time.Date(2017, 3, 14, 15, 9, 26, 53*1000*1000, GMT))
unmarshalHelper2(t, "20170314150926.053[0:GMT]", &d, &overwritten, eq)
unmarshalHelper2(t, "20170314150926.053[+0:GMT]", &d, &overwritten, eq)
unmarshalHelper2(t, "20170314150926.053[-0:GMT]", &d, &overwritten, eq)
unmarshalHelper2(t, "20170314150926.053[0]", &d, &overwritten, eq)
unmarshalHelper2(t, "20170314150926.053[+0]", &d, &overwritten, eq)
unmarshalHelper2(t, "20170314150926.053[-0]", &d, &overwritten, eq)
d = ofxgo.NewDateGMT(2017, 3, 14, 15, 9, 26, 53*1000*1000)
unmarshalHelper2(t, "20170314150926.053[0:GMT]", d, &overwritten, eq)
unmarshalHelper2(t, "20170314150926.053[+0:GMT]", d, &overwritten, eq)
unmarshalHelper2(t, "20170314150926.053[-0:GMT]", d, &overwritten, eq)
unmarshalHelper2(t, "20170314150926.053[0]", d, &overwritten, eq)
unmarshalHelper2(t, "20170314150926.053[+0]", d, &overwritten, eq)
unmarshalHelper2(t, "20170314150926.053[-0]", d, &overwritten, eq)
d = ofxgo.Date(time.Date(2017, 3, 14, 15, 9, 26, 53*1000*1000, NPT))
unmarshalHelper2(t, "20170314150926.053[5.75:NPT]", &d, &overwritten, eq)
d = ofxgo.Date(time.Date(2017, 3, 14, 15, 9, 26, 53*1000*1000, EST))
unmarshalHelper2(t, "20170314150926.053[-5:EST]", &d, &overwritten, eq)
d = ofxgo.Date(time.Date(2017, 3, 14, 15, 9, 26, 53*1000*1000, GMT))
unmarshalHelper2(t, "20170314150926.053[0:GMT]", &d, &overwritten, eq)
d = ofxgo.Date(time.Date(2017, 3, 14, 15, 9, 26, 53*1000*1000, IST))
unmarshalHelper2(t, "20170314150926.053[5.50:IST]", &d, &overwritten, eq)
d = ofxgo.Date(time.Date(2018, 11, 1, 23, 59, 58, 0, EST))
unmarshalHelper2(t, "20181101235958.000[-5:EST]", &d, &overwritten, eq)
d = ofxgo.Date(time.Date(0, 1, 1, 0, 0, 0, 0, IST))
unmarshalHelper2(t, "00000101000000.000[5.50:IST]", &d, &overwritten, eq)
d = ofxgo.Date(time.Unix(0, 0).In(GMT))
unmarshalHelper2(t, "19700101000000.000[0:GMT]", &d, &overwritten, eq)
d = ofxgo.Date(time.Date(2017, 3, 14, 0, 0, 26, 53*1000*1000, EST))
unmarshalHelper2(t, "20170314000026.053[-5:EST]", &d, &overwritten, eq)
d = ofxgo.Date(time.Date(2017, 3, 14, 0, 0, 26, 53*1000*1000, NST))
unmarshalHelper2(t, "20170314000026.053[-3.50:NST]", &d, &overwritten, eq)
d = ofxgo.NewDate(2017, 3, 14, 15, 9, 26, 53*1000*1000, NPT)
unmarshalHelper2(t, "20170314150926.053[5.75:NPT]", d, &overwritten, eq)
d = ofxgo.NewDate(2017, 3, 14, 15, 9, 26, 53*1000*1000, EST)
unmarshalHelper2(t, "20170314150926.053[-5:EST]", d, &overwritten, eq)
d = ofxgo.NewDate(2017, 3, 14, 15, 9, 26, 53*1000*1000, GMT)
unmarshalHelper2(t, "20170314150926.053[0:GMT]", d, &overwritten, eq)
d = ofxgo.NewDate(2017, 3, 14, 15, 9, 26, 53*1000*1000, IST)
unmarshalHelper2(t, "20170314150926.053[5.50:IST]", d, &overwritten, eq)
d = ofxgo.NewDate(2018, 11, 1, 23, 59, 58, 0, EST)
unmarshalHelper2(t, "20181101235958.000[-5:EST]", d, &overwritten, eq)
d = ofxgo.NewDate(0, 1, 1, 0, 0, 0, 0, IST)
unmarshalHelper2(t, "00000101000000.000[5.50:IST]", d, &overwritten, eq)
d = &ofxgo.Date{Time: time.Unix(0, 0).In(GMT)}
unmarshalHelper2(t, "19700101000000.000[0:GMT]", d, &overwritten, eq)
d = ofxgo.NewDate(2017, 3, 14, 0, 0, 26, 53*1000*1000, EST)
unmarshalHelper2(t, "20170314000026.053[-5:EST]", d, &overwritten, eq)
d = ofxgo.NewDate(2017, 3, 14, 0, 0, 26, 53*1000*1000, NST)
unmarshalHelper2(t, "20170314000026.053[-3.50:NST]", d, &overwritten, eq)
// Autopopulate zone without textual description for GMT
d = ofxgo.Date(time.Date(2017, 3, 14, 15, 9, 26, 53*1000*1000, GMT))
unmarshalHelper2(t, "20170314150926.053[0]", &d, &overwritten, eq)
d = ofxgo.NewDate(2017, 3, 14, 15, 9, 26, 53*1000*1000, GMT)
unmarshalHelper2(t, "20170314150926.053[0]", d, &overwritten, eq)
// but not for others:
d = ofxgo.Date(time.Date(2017, 3, 14, 0, 0, 26, 53*1000*1000, NST_nodesc))
unmarshalHelper2(t, "20170314000026.053[-3.50]", &d, &overwritten, eq)
d = ofxgo.NewDate(2017, 3, 14, 0, 0, 26, 53*1000*1000, NST_nodesc)
unmarshalHelper2(t, "20170314000026.053[-3.50]", d, &overwritten, eq)
// Make sure we handle poorly-formatted dates (from Vanguard)
d = ofxgo.Date(time.Date(2016, 12, 7, 16, 0, 0, 0, EST))
unmarshalHelper2(t, "20161207160000.000[-5:EST]610900.500[-9:BST]", &d, &overwritten, eq) // extra part intentionally different to ensure the first timezone is parsed
d = ofxgo.NewDate(2016, 12, 7, 16, 0, 0, 0, EST)
unmarshalHelper2(t, "20161207160000.000[-5:EST]610900.500[-9:BST]", d, &overwritten, eq) // extra part intentionally different to ensure the first timezone is parsed
// Make sure we properly handle ending newlines
d = ofxgo.Date(time.Date(2018, 11, 1, 23, 59, 58, 0, EST))
unmarshalHelper2(t, "20181101235958.000[-5:EST]\n", &d, &overwritten, eq)
d = ofxgo.NewDate(2018, 11, 1, 23, 59, 58, 0, EST)
unmarshalHelper2(t, "20181101235958.000[-5:EST]\n", d, &overwritten, eq)
}
func TestMarshalString(t *testing.T) {