Skip to content

Commit

Permalink
show multiple selected week days in the order of the week day list
Browse files Browse the repository at this point in the history
  • Loading branch information
mayswind committed Aug 26, 2024
1 parent c2fbd91 commit 720f83b
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/components/desktop/ScheduleFrequencySelect.vue
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ export default {
} else if (this.type === templateConstants.allTemplateScheduledFrequencyTypes.Weekly.type) {
if (this.frequencyValue.length) {
return this.$t('format.misc.everyMultiDaysOfWeek', {
days: this.$locale.getMultiWeekdayLongNames(this.frequencyValue)
days: this.$locale.getMultiWeekdayLongNames(this.frequencyValue, this.firstDayOfWeek)
});
} else {
return this.$t('Weekly');
Expand Down
33 changes: 30 additions & 3 deletions src/lib/i18n.js
Original file line number Diff line number Diff line change
Expand Up @@ -350,9 +350,36 @@ function getMultiMonthdayShortNames(monthDays, translateFn) {
}
}

function getMultiWeekdayLongNames(weekdayTypes, translateFn) {
function getMultiWeekdayLongNames(weekdayTypes, firstDayOfWeek, translateFn) {
const weekdayTypesMap = {};
const finalWeekdayTypes = [];

if (!isNumber(firstDayOfWeek)) {
firstDayOfWeek = datetimeConstants.allWeekDays.Sunday.type;
}

for (let i = 0; i < weekdayTypes.length; i++) {
weekdayTypesMap[weekdayTypes[i]] = true;
}

for (let i = firstDayOfWeek; i < datetimeConstants.allWeekDaysArray.length; i++) {
const weekDay = datetimeConstants.allWeekDaysArray[i];

if (weekdayTypesMap[weekDay.type]) {
finalWeekdayTypes.push(weekDay.type);
}
}

for (let i = 0; i < firstDayOfWeek; i++) {
const weekDay = datetimeConstants.allWeekDaysArray[i];

if (weekdayTypesMap[weekDay.type]) {
finalWeekdayTypes.push(weekDay.type);
}
}

const allWeekDays = getAllWeekDays(null, translateFn)
return joinMultiText(weekdayTypes.map(type => getNameByKeyValue(allWeekDays, type, 'type', 'displayName')), translateFn);
return joinMultiText(finalWeekdayTypes.map(type => getNameByKeyValue(allWeekDays, type, 'type', 'displayName')), translateFn);
}

function getI18nLongDateFormat(translateFn, formatTypeValue) {
Expand Down Expand Up @@ -1515,7 +1542,7 @@ export function i18nFunctions(i18nGlobal) {
getWeekdayShortName: (weekDay) => getWeekdayShortName(weekDay, i18nGlobal.t),
getWeekdayLongName: (weekDay) => getWeekdayLongName(weekDay, i18nGlobal.t),
getMultiMonthdayShortNames: (monthdays) => getMultiMonthdayShortNames(monthdays, i18nGlobal.t),
getMultiWeekdayLongNames: (weekdayTypes) => getMultiWeekdayLongNames(weekdayTypes, i18nGlobal.t),
getMultiWeekdayLongNames: (weekdayTypes, firstDayOfWeek) => getMultiWeekdayLongNames(weekdayTypes, firstDayOfWeek, i18nGlobal.t),
formatUnixTimeToLongDateTime: (userStore, unixTime, utcOffset, currentUtcOffset) => formatUnixTime(unixTime, getI18nLongDateFormat(i18nGlobal.t, userStore.currentUserLongDateFormat) + ' ' + getI18nLongTimeFormat(i18nGlobal.t, userStore.currentUserLongTimeFormat), utcOffset, currentUtcOffset),
formatUnixTimeToShortDateTime: (userStore, unixTime, utcOffset, currentUtcOffset) => formatUnixTime(unixTime, getI18nShortDateFormat(i18nGlobal.t, userStore.currentUserShortDateFormat) + ' ' + getI18nShortTimeFormat(i18nGlobal.t, userStore.currentUserShortTimeFormat), utcOffset, currentUtcOffset),
formatUnixTimeToLongDate: (userStore, unixTime, utcOffset, currentUtcOffset) => formatUnixTime(unixTime, getI18nLongDateFormat(i18nGlobal.t, userStore.currentUserLongDateFormat), utcOffset, currentUtcOffset),
Expand Down
5 changes: 4 additions & 1 deletion src/views/mobile/transactions/EditPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,9 @@ export default {
defaultAccountId() {
return this.userStore.currentUserDefaultAccountId;
},
firstDayOfWeek() {
return this.userStore.currentUserFirstDayOfWeek;
},
allTransactionTypes() {
return transactionConstants.allTransactionTypes;
},
Expand Down Expand Up @@ -628,7 +631,7 @@ export default {
if (this.transaction.scheduledFrequencyType === templateConstants.allTemplateScheduledFrequencyTypes.Weekly.type) {
if (scheduledFrequencyValues.length) {
return this.$t('format.misc.everyMultiDaysOfWeek', {
days: this.$locale.getMultiWeekdayLongNames(scheduledFrequencyValues)
days: this.$locale.getMultiWeekdayLongNames(scheduledFrequencyValues, this.firstDayOfWeek)
});
} else {
return this.$t('Weekly');
Expand Down

0 comments on commit 720f83b

Please sign in to comment.