Skip to content

Commit

Permalink
use the preset name if custom date range matches a preset item
Browse files Browse the repository at this point in the history
  • Loading branch information
mayswind committed Jun 2, 2024
1 parent 809172b commit 72f6a9e
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 11 deletions.
18 changes: 12 additions & 6 deletions src/lib/datetime.js
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,16 @@ export function getShiftedDateRange(minTime, maxTime, scale) {

export function getShiftedDateRangeAndDateType(minTime, maxTime, scale, firstDayOfWeek, scene) {
const newDateRange = getShiftedDateRange(minTime, maxTime, scale);
const newDateType = getDateTypeByDateRange(newDateRange.minTime, newDateRange.maxTime, firstDayOfWeek, scene);

return {
dateType: newDateType,
minTime: newDateRange.minTime,
maxTime: newDateRange.maxTime
};
}

export function getDateTypeByDateRange(minTime, maxTime, firstDayOfWeek, scene) {
let newDateType = dateTimeConstants.allDateRanges.Custom.type;

for (let dateRangeField in dateTimeConstants.allDateRanges) {
Expand All @@ -381,17 +391,13 @@ export function getShiftedDateRangeAndDateType(minTime, maxTime, scale, firstDay

const dateRange = getDateRangeByDateType(dateRangeType.type, firstDayOfWeek);

if (dateRange && dateRange.minTime === newDateRange.minTime && dateRange.maxTime === newDateRange.maxTime) {
if (dateRange && dateRange.minTime === minTime && dateRange.maxTime === maxTime) {
newDateType = dateRangeType.type;
break;
}
}

return {
dateType: newDateType,
minTime: newDateRange.minTime,
maxTime: newDateRange.maxTime
};
return newDateType;
}

export function getDateRangeByDateType(dateType, firstDayOfWeek) {
Expand Down
9 changes: 7 additions & 2 deletions src/views/desktop/statistics/TransactionPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,7 @@ import {
getYearMonthFirstUnixTime,
getYearMonthLastUnixTime,
getShiftedDateRangeAndDateType,
getDateTypeByDateRange,
getDateRangeByDateType
} from '@/lib/datetime.js';
import { isChartDataTypeAvailableForAnalysisType } from '@/lib/statistics.js';
Expand Down Expand Up @@ -648,16 +649,20 @@ export default {
}
if (this.analysisType === statisticsConstants.allAnalysisTypes.CategoricalAnalysis) {
const chartDateType = getDateTypeByDateRange(startTime, endTime, this.firstDayOfWeek, datetimeConstants.allDateRangeScenes.Normal);
this.statisticsStore.updateTransactionStatisticsFilter({
categoricalChartDateType: this.allDateRanges.Custom.type,
categoricalChartDateType: chartDateType,
categoricalChartStartTime: startTime,
categoricalChartEndTime: endTime
});
this.showCustomDateRangeDialog = false;
} else if (this.analysisType === statisticsConstants.allAnalysisTypes.TrendAnalysis) {
const chartDateType = getDateTypeByDateRange(getYearMonthFirstUnixTime(startTime), getYearMonthLastUnixTime(endTime), this.firstDayOfWeek, datetimeConstants.allDateRangeScenes.TrendAnalysis);
this.statisticsStore.updateTransactionStatisticsFilter({
trendChartDateType: this.allDateRanges.Custom.type,
trendChartDateType: chartDateType,
trendChartStartYearMonth: startTime,
trendChartEndYearMonth: endTime
});
Expand Down
5 changes: 4 additions & 1 deletion src/views/desktop/transactions/ListPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,7 @@ import {
getBrowserTimezoneOffsetMinutes,
getActualUnixTimeForStore,
getShiftedDateRangeAndDateType,
getDateTypeByDateRange,
getDateRangeByDateType,
getRecentDateRangeType,
isDateRangeMatchOneMonth
Expand Down Expand Up @@ -797,8 +798,10 @@ export default {
return;
}
const dateType = getDateTypeByDateRange(minTime, maxTime, this.firstDayOfWeek, datetimeConstants.allDateRangeScenes.Normal);
this.transactionsStore.updateTransactionListFilter({
dateType: datetimeConstants.allDateRanges.Custom.type,
dateType: dateType,
maxTime: maxTime,
minTime: minTime
});
Expand Down
5 changes: 4 additions & 1 deletion src/views/mobile/statistics/TransactionPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,7 @@ import statisticsConstants from '@/consts/statistics.js';
import { getNameByKeyValue, limitText, formatPercent } from '@/lib/common.js'
import {
getShiftedDateRangeAndDateType,
getDateTypeByDateRange,
getDateRangeByDateType
} from '@/lib/datetime.js';
import { scrollToSelectedItem } from '@/lib/ui.mobile.js';
Expand Down Expand Up @@ -492,8 +493,10 @@ export default {
return;
}
const chartDateType = getDateTypeByDateRange(startTime, endTime, this.firstDayOfWeek, datetimeConstants.allDateRangeScenes.Normal);
this.statisticsStore.updateTransactionStatisticsFilter({
categoricalChartDateType: this.allDateRanges.Custom.type,
categoricalChartDateType: chartDateType,
categoricalChartStartTime: startTime,
categoricalChartEndTime: endTime
});
Expand Down
5 changes: 4 additions & 1 deletion src/views/mobile/transactions/ListPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,7 @@ import {
getBrowserTimezoneOffsetMinutes,
getActualUnixTimeForStore,
getShiftedDateRangeAndDateType,
getDateTypeByDateRange,
getDateRangeByDateType
} from '@/lib/datetime.js';
import { categoryTypeToTransactionType, transactionTypeToCategoryType } from '@/lib/category.js';
Expand Down Expand Up @@ -720,8 +721,10 @@ export default {
return;
}
const dateType = getDateTypeByDateRange(minTime, maxTime, this.firstDayOfWeek, datetimeConstants.allDateRangeScenes.Normal);
this.transactionsStore.updateTransactionListFilter({
dateType: this.allDateRanges.Custom.type,
dateType: dateType,
maxTime: maxTime,
minTime: minTime
});
Expand Down

0 comments on commit 72f6a9e

Please sign in to comment.