From f42f02bd54da96cc7b80c0531878506396383dca Mon Sep 17 00:00:00 2001 From: MaysWind Date: Wed, 30 Dec 2020 01:34:08 +0800 Subject: [PATCH] fix month format error in ios --- src/lib/utils.js | 12 ++++++++++++ src/views/mobile/transactions/List.vue | 3 ++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/lib/utils.js b/src/lib/utils.js index 041f570e..45c71689 100644 --- a/src/lib/utils.js +++ b/src/lib/utils.js @@ -57,6 +57,17 @@ function getMonth(date) { return moment(date).month() + 1; } +function getYearAndMonth(date) { + const year = getYear(date); + let month = getMonth(date); + + if (month < 10) { + month = '0' + month; + } + + return `${year}-${month}`; +} + function getDay(date) { return moment(date).date(); } @@ -428,6 +439,7 @@ export default { getUnixTime, getYear, getMonth, + getYearAndMonth, getDay, getDayOfWeek, copyObjectTo, diff --git a/src/views/mobile/transactions/List.vue b/src/views/mobile/transactions/List.vue index 25cbe804..afcb1d8e 100644 --- a/src/views/mobile/transactions/List.vue +++ b/src/views/mobile/transactions/List.vue @@ -504,6 +504,7 @@ export default { const transactionYear = this.$utilities.getYear(transactionTime); const transactionMonth = this.$utilities.getMonth(transactionTime); + const transactionYearMonth = this.$utilities.getYearAndMonth(transactionTime); if (currentMonthList && currentMonthList.year === transactionYear && currentMonthList.month === transactionMonth) { currentMonthList.items.push(transaction); @@ -534,7 +535,7 @@ export default { this.transactions.push({ year: transactionYear, month: transactionMonth, - yearMonth: `${transactionYear}-${transactionMonth}`, + yearMonth: transactionYearMonth, opened: autoExpand, items: [] });