Skip to content

Commit

Permalink
Fix OCBC breaking their credit date format
Browse files Browse the repository at this point in the history
  • Loading branch information
ystxn committed Oct 6, 2024
1 parent 70169a4 commit 699d9b6
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 12 deletions.
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.9-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10.2-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
5 changes: 4 additions & 1 deletion gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
# SPDX-License-Identifier: Apache-2.0
#

##############################################################################
#
Expand Down Expand Up @@ -84,7 +86,8 @@ done
# shellcheck disable=SC2034
APP_BASE_NAME=${0##*/}
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit
APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s
' "$PWD" ) || exit

# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD=maximum
Expand Down
2 changes: 2 additions & 0 deletions gradlew.bat
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
@rem See the License for the specific language governing permissions and
@rem limitations under the License.
@rem
@rem SPDX-License-Identifier: Apache-2.0
@rem

@if "%DEBUG%"=="" @echo off
@rem ##########################################################################
Expand Down
7 changes: 4 additions & 3 deletions src/main/java/tech/sledger/service/importer/OcbcImporter.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@

@Slf4j
public class OcbcImporter implements Importer {
private final DateTimeFormatter dateFormat = DateTimeFormatter.ofPattern("d/M/yyyy");
private final DateTimeFormatter dateFormat1 = DateTimeFormatter.ofPattern("d/M/yyyy");
private final DateTimeFormatter dateFormat2 = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.S");

@Override
public List<Transaction> process(
Expand Down Expand Up @@ -77,7 +78,7 @@ private List<Transaction> processCash(List<String[]> data, Account account, List
completeTransaction(tx, tx.getRemarks(), templates);
output.add(tx);
}
Instant date = LocalDate.parse(row[0], dateFormat)
Instant date = LocalDate.parse(row[0], dateFormat1)
.atStartOfDay(ZoneOffset.UTC).toInstant();
BigDecimal debit = parseDecimal(row[3]);
BigDecimal credit = parseDecimal(row[4]);
Expand All @@ -103,7 +104,7 @@ private List<Transaction> processCash(List<String[]> data, Account account, List
private List<Transaction> processCredit(List<String[]> data, Account account, List<Template> templates) {
List<Transaction> output = new ArrayList<>();
for (String[] row : data) {
LocalDate localDate = LocalDate.parse(row[0], dateFormat);
LocalDate localDate = LocalDate.parse(row[0], dateFormat2);
Instant date = localDate.atStartOfDay(ZoneOffset.UTC).toInstant();
Instant billingMonth = getBillingMonth(localDate, (CreditAccount) account);
Template template = matchTemplate(cleanCreditRemarks(row[1]), templates);
Expand Down
16 changes: 9 additions & 7 deletions src/test/java/tech/sledger/ImportTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,13 @@ public class ImportTests extends BaseTest {
Credit limit,"SGD 1,234.56"
Credit left,"SGD 321.23"
Transaction History
Main Credit CardOCBC 365 Credit Card 1111-1111-1111-1111
Transaction history
Main credit card OCBC INFINITY Cashback Card 5413-8301-0004-9600
Transaction date,Description,Withdrawals (SGD),Deposits (SGD)
04/05/2023,SHOPPING,30.41,
01/05/2023,Household Stuff,0.12,
2024-09-02 00:00:00.0,-9489 KOUFU PTE LTD Singapore SGP,2.60,
2024-09-02 00:00:00.0,-9489 BUS/MRT 498357444SINGAPORE SGP,7.62,
2024-08-31 00:00:00.0,-9489 BUS/MRT CM8880515SINGAPORE SGP,,1.21
2024-08-31 00:00:00.0,-9489 PIZZAKAYA-JEM SINGAPORE SGP,46.28,
""".getBytes(UTF_8);
Map<String, byte[]> ocbcCsv = Map.of(
"ocbc-cash.csv", ocbcCashCsv,
Expand Down Expand Up @@ -249,16 +251,16 @@ public void ocbcCredit() throws Exception {
.file(mockFile("ocbc-credit.csv"));
mvc.perform(request)
.andExpect(status().isOk())
.andExpect(jsonPath("$", iterableWithSize(2)))
.andExpect(jsonPath("$.[?(@.remarks == 'Household Stuff')]").exists());
.andExpect(jsonPath("$", iterableWithSize(4)))
.andExpect(jsonPath("$.[?(@.remarks == 'Bus/Mrt Cm8880515')]").exists());

request = MockMvcRequestBuilders
.multipart("/api/import")
.part(new MockPart("accountId", String.valueOf(ocbcCreditAccountId2).getBytes()))
.file(mockFile("ocbc-credit.csv"));
mvc.perform(request)
.andExpect(status().isOk())
.andExpect(jsonPath("$.[0].billingMonth").value("2023-04-01T00:00:00Z"));
.andExpect(jsonPath("$.[0].billingMonth").value("2024-08-01T00:00:00Z"));
}

@Test
Expand Down

0 comments on commit 699d9b6

Please sign in to comment.