From 58145ad96c845644cfe413ca868a10c1f85607c6 Mon Sep 17 00:00:00 2001 From: Mathias Madsen Stav Date: Tue, 13 Oct 2020 14:07:15 +0200 Subject: [PATCH] fix: date exeptions --- prettier.config.js | 7 +++ .../resources/src/js/modules/exceptions.js | 12 ++--- .../resources/src/js/util/helpers.js | 3 ++ .../fields/CalendarizeField_input.twig | 7 +-- src/translations/nb/calendarize.php | 44 +++++++++++++++++++ 5 files changed, 64 insertions(+), 9 deletions(-) create mode 100644 prettier.config.js create mode 100644 src/translations/nb/calendarize.php diff --git a/prettier.config.js b/prettier.config.js new file mode 100644 index 0000000..1ec6b20 --- /dev/null +++ b/prettier.config.js @@ -0,0 +1,7 @@ +module.exports = { + trailingComma: 'es5', + tabWidth: 4, + semi: true, + singleQuote: true, + printWidth: 120, +}; diff --git a/src/assetbundles/resources/src/js/modules/exceptions.js b/src/assetbundles/resources/src/js/modules/exceptions.js index 2eec39a..d1f51fc 100644 --- a/src/assetbundles/resources/src/js/modules/exceptions.js +++ b/src/assetbundles/resources/src/js/modules/exceptions.js @@ -1,6 +1,4 @@ -import { - getDayName -} from '../util/helpers'; +import { getLocalizeMoment, getLocalizedDayName } from '../util/helpers'; // helper method const removeChild = (item, child) => { @@ -54,10 +52,12 @@ class CalendarException { close.setAttribute('data-icon', 'remove'); close.addEventListener('click', () => { removeChild(this.listing, li); - }) + }); // create base inputs - const newValue = this.dateField.value; + const localizedMoment = getLocalizeMoment(this.dateField.value); + let newValue = localizedMoment.format('D/M/Y'); + const name = this.hiddenName; const position = name.indexOf('[date]'); const newFieldName = [name.slice(0, position), `[${length || 0}]`, name.slice(position)].join(''); @@ -65,7 +65,7 @@ class CalendarException { const hidden = this.createInput(newFieldName, 'hidden', newValue); const timezone = this.createInput(newFieldName.replace('date', 'timezone'), 'hidden', Craft.timezone); - p.innerHTML = getDayName(newValue) + ', ' + newValue; + p.innerHTML = getLocalizedDayName(localizedMoment) + ', ' + localizedMoment.format('L'); li.appendChild(close); li.appendChild(hidden); diff --git a/src/assetbundles/resources/src/js/util/helpers.js b/src/assetbundles/resources/src/js/util/helpers.js index 2290513..997fad1 100644 --- a/src/assetbundles/resources/src/js/util/helpers.js +++ b/src/assetbundles/resources/src/js/util/helpers.js @@ -14,6 +14,9 @@ export const getDayName = (date) => { return days[d.getDay()]; }; +export const getLocalizedDayName = (mom) => { + return mom.format('dddd'); +}; export const weekOfMonth = (date) => { const m = moment(date); let w = m.isoWeekday(7).week() - moment(m).startOf('month').isoWeekday(7).week() - 1; diff --git a/src/templates/_components/fields/CalendarizeField_input.twig b/src/templates/_components/fields/CalendarizeField_input.twig index 993241c..4c3d944 100644 --- a/src/templates/_components/fields/CalendarizeField_input.twig +++ b/src/templates/_components/fields/CalendarizeField_input.twig @@ -184,9 +184,10 @@ {% if value.exceptions is defined %} {% for key, exception in value.exceptions %}
  • -

    {{ exception | date('l, m/d/Y') }}

    - - +
    +

    {{ exception | date('l, d/m/Y') }}

    + +
  • {% endfor %} {% endif %} diff --git a/src/translations/nb/calendarize.php b/src/translations/nb/calendarize.php new file mode 100644 index 0000000..833a04b --- /dev/null +++ b/src/translations/nb/calendarize.php @@ -0,0 +1,44 @@ + 'Calendarize plugin lastet', + 'Sun' => 'Sun', + 'Mon' => 'Man', + 'Tue' => 'Tir', + 'Wed' => 'Ons', + 'Thu' => 'Tor', + 'Fri' => 'Fre', + 'Sat' => 'Lør', + 'to' => 'til', + 'Never' => 'Aldri', + 'On Date' => 'På dato', + 'Daily' => 'Dag', + 'Weekly' => 'Uke', + 'Biweekly (every 2 weeks)' => '2 uker', + 'Monthly' => 'Måned', + 'Yearly' => 'år', + 'All Day' => 'Hele dagen', + 'Repeats' => 'Repeterer', + 'Every' => 'Hver', + 'Every month on the' => 'Hver måned den', + 'Ends Repeat' => 'Slutter repetering', + 'Date Exceptions' => 'Dato unntak', + 'Time Exceptions' => 'Tids unntak', + 'Occurrences' => 'Hendelser', + 'Last Occurrence' => 'Siste hendelse', + 'Next Occurrence' => 'Neste hendelse', + 'Date' => 'Dato' +];