Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
SWE-12 use new date formatter
- several commits ago we created `careCreditDateFormatter`
- replace usage of regular `DateFormatter` which require setting of format style and locale in each instance to `static` property which automatically returns the date formatter we want
  • Loading branch information
ahm11003 committed Apr 5, 2019
1 parent d4bf1b8 commit be8b0cf
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 15 deletions.
Expand Up @@ -43,17 +43,14 @@ class FetchData {
guard dict["status"]?.dictionaryValue["response_code"]?.string == "0" else { return } guard dict["status"]?.dictionaryValue["response_code"]?.string == "0" else { return }
//print(json) //print(json)
let formatter = DateFormatter()
formatter.locale = Locale.current
formatter.dateFormat = "yyyyMMdd"
if let accounts = dict["account_number_list"]?.arrayValue { if let accounts = dict["account_number_list"]?.arrayValue {
accounts.forEach { accounts.forEach {
if let accountAlias = $0.dictionaryValue["account_alias"]?.string, if let accountAlias = $0.dictionaryValue["account_alias"]?.string,
let last4 = $0["last4_acct_number"].string, let last4 = $0["last4_acct_number"].string,
let creditLimitString = $0.dictionaryValue["credit_limit"]?.string, let creditLimitString = $0.dictionaryValue["credit_limit"]?.string,
let creditLimit = Double(creditLimitString), let creditLimit = Double(creditLimitString),
let payDueDateString = $0.dictionaryValue["next_payment_due_date"]?.string, let payDueDateString = $0.dictionaryValue["next_payment_due_date"]?.string,
let paymentDueDate = formatter.date(from: payDueDateString), let paymentDueDate = Defaults.careCreditDateFormatter.date(from: payDueDateString),
let curBalString = $0.dictionaryValue["current_balance"]?.string, let curBalString = $0.dictionaryValue["current_balance"]?.string,
let currentBalance = Double(curBalString), let currentBalance = Double(curBalString),
let availCreditString = $0.dictionaryValue["available_credit"]?.string, let availCreditString = $0.dictionaryValue["available_credit"]?.string,
Expand Down Expand Up @@ -81,9 +78,6 @@ class FetchData {
var header = Defaults.headerForTransaction var header = Defaults.headerForTransaction
header["account_alias"] = accountAlias header["account_alias"] = accountAlias
var transactions: [Transaction] = [] var transactions: [Transaction] = []
let formatter = DateFormatter()
formatter.locale = Locale.current
formatter.dateFormat = "yyyyMMdd"


Alamofire.request(Defaults.TRANS_HISTORY_URL, method: .post, parameters: header, encoding: JSONEncoding.default, headers: Defaults.authHeader).responseJSON { payload in Alamofire.request(Defaults.TRANS_HISTORY_URL, method: .post, parameters: header, encoding: JSONEncoding.default, headers: Defaults.authHeader).responseJSON { payload in
switch payload.result { switch payload.result {
Expand All @@ -94,7 +88,7 @@ class FetchData {
//let's first parse the pending transactions //let's first parse the pending transactions
dict["pending_transaction_list"]?.arrayValue.forEach { dict["pending_transaction_list"]?.arrayValue.forEach {
if let desc = $0["description"].string, if let desc = $0["description"].string,
let date = formatter.date(from: $0["transaction_date"].stringValue), let date = Defaults.careCreditDateFormatter.date(from: $0["transaction_date"].stringValue),
let amountString = $0["transaction_amount"].string, let amountString = $0["transaction_amount"].string,
let amount = Double(amountString), let amount = Double(amountString),
let confirmationNum = $0["payment_confirmation_number"].string, let confirmationNum = $0["payment_confirmation_number"].string,
Expand All @@ -111,7 +105,7 @@ class FetchData {
// let's parse just processed transactions now // let's parse just processed transactions now
dict["processed_transaction_list"]?.arrayValue.forEach { dict["processed_transaction_list"]?.arrayValue.forEach {
if let desc = $0["description"].string, if let desc = $0["description"].string,
let date = formatter.date(from: $0["transaction_date"].stringValue), let date = Defaults.careCreditDateFormatter.date(from: $0["transaction_date"].stringValue),
let amountString = $0["transaction_amount"].string, let amountString = $0["transaction_amount"].string,
let amount = Double(amountString) { let amount = Double(amountString) {
let type: TransactionType = $0["payment_amount_type"].stringValue == "" ? .purchase : .reimbursement let type: TransactionType = $0["payment_amount_type"].stringValue == "" ? .purchase : .reimbursement
Expand Down
8 changes: 2 additions & 6 deletions SynchronyFinancial/SynchronyFinancial/Defaults.swift
Expand Up @@ -54,13 +54,9 @@ final class Defaults {
var account_alias = "" var account_alias = ""


// Dates // Dates
let formatter = DateFormatter()
formatter.locale = Locale.current
formatter.dateFormat = "yyyyMMdd"

// for now lets get transactions from the past 2 weeks // for now lets get transactions from the past 2 weeks
let start_date = formatter.string(from: Calendar.current.date(byAdding: .day, value: -14, to: Date()) ?? Date()) let start_date = careCreditDateFormatter.string(from: Calendar.current.date(byAdding: .day, value: -14, to: Date()) ?? Date())
let end_date = formatter.string(from: Date()) let end_date = careCreditDateFormatter.string(from: Date())


return ["account_alias": account_alias, return ["account_alias": account_alias,
"begin_sequence": "1", "begin_sequence": "1",
Expand Down

0 comments on commit be8b0cf

Please sign in to comment.