Skip to content

Commit

Permalink
fix: use first day of week setting from server
Browse files Browse the repository at this point in the history
Initialize moment, FullCalender and our date picker using the global
first day of week setting from server. It is currently derived from a
user's locale and provided by `@nextcloud/l10n`.

Signed-off-by: Richard Steinmetz <richard@steinmetz.cloud>
  • Loading branch information
st3iny committed Jul 10, 2024
1 parent 4485575 commit 3203378
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 17 deletions.
7 changes: 2 additions & 5 deletions src/fullcalendar/localization/localeProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@
* SPDX-FileCopyrightText: 2020 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
import { translate as t, getLanguage } from '@nextcloud/l10n'
import {
getFirstDayOfWeekFromMomentLocale,
} from '../../utils/moment.js'
import { translate as t, getLanguage, getFirstDay } from '@nextcloud/l10n'

/**
* Returns localization settings for the FullCalender package.
Expand All @@ -15,7 +12,7 @@ import {
*/
const getFullCalendarLocale = () => {
return {
firstDay: getFirstDayOfWeekFromMomentLocale(),
firstDay: getFirstDay(),
locale: getLanguage(),
// TRANSLATORS W is an abbreviation for Week
weekText: t('calendar', 'W'),
Expand Down
3 changes: 2 additions & 1 deletion src/utils/localization.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
getDayNames,
getDayNamesMin,
getDayNamesShort,
getFirstDay,
getMonthNames,
getMonthNamesShort,
} from '@nextcloud/l10n'
Expand All @@ -31,7 +32,7 @@ const getLangConfigForVue2DatePicker = (momentLocale) => {
weekdays: getDayNames(),
weekdaysShort: getDayNamesShort(),
weekdaysMin: getDayNamesMin(),
firstDayOfWeek: moment.localeData(momentLocale).firstDayOfWeek(),
firstDayOfWeek: getFirstDay(),
firstWeekContainsDate: moment.localeData(momentLocale).firstDayOfYear(),
meridiem: moment.localeData(momentLocale).meridiem,
meridiemParse: moment.localeData(momentLocale).meridiemParse,
Expand Down
13 changes: 2 additions & 11 deletions src/utils/moment.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* SPDX-FileCopyrightText: 2018 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
import { getLanguage, getLocale } from '@nextcloud/l10n'
import { getFirstDay, getLanguage, getLocale } from '@nextcloud/l10n'
import moment from '@nextcloud/moment'

/**
Expand Down Expand Up @@ -38,7 +38,7 @@ export default async function loadMomentLocalization() {
llll: moment.localeData(realLocale).longDateFormat('llll'),
},
week: {
dow: moment.localeData(realLocale).firstDayOfWeek(),
dow: getFirstDay(),
doy: moment.localeData(realLocale).firstDayOfYear(),
},
})
Expand Down Expand Up @@ -77,12 +77,3 @@ async function getLocaleFor(locale) {

return 'en'
}

/**
* Get's the first day of a week based on a moment locale
*
* @return {number}
*/
export function getFirstDayOfWeekFromMomentLocale() {
return moment.localeData().firstDayOfWeek()
}

0 comments on commit 3203378

Please sign in to comment.