From 28dc2e425a3dc6d70e95953607be68a8efd92f90 Mon Sep 17 00:00:00 2001 From: MaysWind Date: Thu, 15 Jun 2023 01:27:15 +0800 Subject: [PATCH] fix the problem the end time not equals to the current time in transaction list page when timezone not set to browser timezone --- src/lib/datetime.js | 4 ++++ src/views/mobile/transactions/ListPage.vue | 9 +++++++++ 2 files changed, 13 insertions(+) diff --git a/src/lib/datetime.js b/src/lib/datetime.js index 017e34e6..7e4b6924 100644 --- a/src/lib/datetime.js +++ b/src/lib/datetime.js @@ -204,6 +204,10 @@ export function getThisYearLastUnixTime() { return moment.unix(getThisYearFirstUnixTime()).add(1, 'years').subtract(1, 'seconds').unix(); } +export function getSpecifiedDayFirstUnixTime(unixTime) { + return moment.unix(unixTime).set({ hour: 0, minute: 0, second: 0, millisecond: 0 }).unix(); +} + export function getDateTimeFormatType(allFormatMap, allFormatArray, localeDefaultFormatTypeName, systemDefaultFormatType, formatTypeValue) { if (formatTypeValue > dateTimeConstants.defaultDateTimeFormatValue && allFormatArray[formatTypeValue - 1] && allFormatArray[formatTypeValue - 1].key) { return allFormatArray[formatTypeValue - 1]; diff --git a/src/views/mobile/transactions/ListPage.vue b/src/views/mobile/transactions/ListPage.vue index 416b87aa..3e5b8715 100644 --- a/src/views/mobile/transactions/ListPage.vue +++ b/src/views/mobile/transactions/ListPage.vue @@ -424,8 +424,12 @@ import accountConstants from '@/consts/account.js'; import transactionConstants from '@/consts/transaction.js'; import { getNameByKeyValue } from '@/lib/common.js'; import { + getCurrentUnixTime, + getSpecifiedDayFirstUnixTime, getUtcOffsetByUtcOffsetMinutes, getTimezoneOffsetMinutes, + getBrowserTimezoneOffsetMinutes, + getActualUnixTimeForStore, getDateRangeByDateType } from '@/lib/datetime.js'; import { categoryTypeToTransactionType, transactionTypeToCategoryType } from '@/lib/category.js'; @@ -659,6 +663,11 @@ export default { }, changeDateFilter(dateType) { if (dateType === this.allDateRanges.Custom.type) { // Custom + if (!this.query.minTime || !this.query.maxTime) { + this.query.maxTime = getActualUnixTimeForStore(getCurrentUnixTime(), getTimezoneOffsetMinutes(), getBrowserTimezoneOffsetMinutes()); + this.query.minTime = getSpecifiedDayFirstUnixTime(this.query.maxTime); + } + this.showCustomDateRangeSheet = true; this.showDatePopover = false; return;