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') }}
+ +